This commit is contained in:
xx 2025-01-24 20:14:00 +01:00 committed by GitHub
commit fb675ba6a7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 132 additions and 7 deletions

View file

@ -11,17 +11,23 @@ class DingDing extends NotificationProvider {
*/
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
const okMsg = "Sent Successfully.";
const mentionAll = notification.mentioning === "everyone";
const mobileList = notification.mentioning === "specify-mobiles" ? notification.mobileList : [];
const userList = notification.mentioning === "specify-users" ? notification.userList : [];
const finalList = [ ...mobileList || [], ...userList || [] ];
const mentionStr = finalList.length > 0 ? "\n" : "" + finalList.map(item => `@${item}`).join(" ");
try {
if (heartbeatJSON != null) {
let params = {
msgtype: "markdown",
markdown: {
title: `[${this.statusToString(heartbeatJSON["status"])}] ${monitorJSON["name"]}`,
text: `## [${this.statusToString(heartbeatJSON["status"])}] ${monitorJSON["name"]} \n> ${heartbeatJSON["msg"]}\n> Time (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`,
text: `## [${this.statusToString(heartbeatJSON["status"])}] ${monitorJSON["name"]} \n> ${heartbeatJSON["msg"]}\n> Time (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}${mentionStr}`,
},
"at": {
"isAtAll": notification.mentioning === "everyone"
at: {
isAtAll: mentionAll,
atUserIds: userList,
atMobiles: mobileList
}
};
if (await this.sendToDingDing(notification, params)) {
@ -31,7 +37,12 @@ class DingDing extends NotificationProvider {
let params = {
msgtype: "text",
text: {
content: msg
content: `${msg}${mentionStr}`
},
at: {
isAtAll: mentionAll,
atUserIds: userList,
atMobiles: mobileList
}
};
if (await this.sendToDingDing(notification, params)) {

View file

@ -16,22 +16,128 @@
</div>
<div class="mb-3">
<label for="mentioning" class="form-label">{{ $t("Mentioning") }}<span style="color: red;"><sup>*</sup></span></label>
<select id="mentioning" v-model="$parent.notification.mentioning" class="form-select" required>
<select id="mentioning" v-model="$parent.notification.mentioning" class="form-select" required @change="onMentioningChange">
<option value="nobody">{{ $t("Don't mention people") }}</option>
<option value="everyone">{{ $t("Mention group", { group: "@everyone" }) }}</option>
<option value="specify-mobiles">{{ $t("Mention Mobile List") }}</option>
<option value="specify-users">{{ $t("Mention User List") }}</option>
</select>
</div>
<div v-if="$parent.notification.mentioning === 'specify-mobiles'" class="mb-3">
<label for="mobileList" class="form-label">{{ $t("Dingtalk Mobile List") }}<span style="color: red;"><sup>*</sup></span></label>
<VueMultiselect
id="mobileList-select"
v-model="$parent.notification.mobileList"
:required="$parent.notification.mentioning === 'specify-mobiles'"
:placeholder="$t('Enter a list of mobile')"
:multiple="true"
:options="mobileOpts"
:max-height="500"
:taggable="true"
:show-no-options="false"
:close-on-select="false"
:clear-on-select="false"
:preserve-search="false"
:preselect-first="false"
@remove="removeMobile"
@tag="addMobile"
></VueMultiselect>
</div>
<div v-if="$parent.notification.mentioning === 'specify-users'" class="mb-3">
<label for="userList" class="form-label">{{ $t("Dingtalk User List") }}<span style="color: red;"><sup>*</sup></span></label>
<VueMultiselect
id="userList-select"
v-model="$parent.notification.userList"
:required="$parent.notification.mentioning === 'specify-users'"
:placeholder="$t('Enter a list of userId')"
:multiple="true"
:options="userIdOpts"
:max-height="500"
:taggable="true"
:show-no-options="false"
:close-on-select="false"
:clear-on-select="true"
:preserve-search="false"
:preselect-first="false"
@remove="removeUser"
@tag="addUser"
></VueMultiselect>
</div>
</template>
<script lang="ts">
import HiddenInput from "../HiddenInput.vue";
import VueMultiselect from "vue-multiselect";
export default {
components: { HiddenInput },
components: {
HiddenInput,
VueMultiselect
},
data() {
return {
mobileOpts: [],
userIdOpts: [],
};
},
mounted() {
if (typeof this.$parent.notification.mentioning === "undefined") {
this.$parent.notification.mentioning = "nobody";
}
if (typeof this.$parent.notification.mobileList === "undefined") {
this.$parent.notification.mobileList = [];
} else {
this.mobileOpts = this.$parent.notification.mobileList;
}
if (typeof this.$parent.notification.userList === "undefined") {
this.$parent.notification.userList = [];
} else {
this.userIdOpts = this.$parent.notification.userList;
}
},
methods: {
onMentioningChange(e) {
if (e.target.value === "specify-mobiles") {
this.$parent.notification.userList = [];
} else if (e.target.value === "specify-users") {
this.$parent.notification.mobileList = [];
} else {
this.$parent.notification.userList = [];
this.$parent.notification.mobileList = [];
}
},
addMobile(mobile) {
const trimmedMobile = mobile.trim();
const chinaMobileRegex = /^1[3-9]\d{9}$/;
if (!chinaMobileRegex.test(trimmedMobile)) {
this.$root.toastError(this.$t("Invalid mobile", { "mobile": trimmedMobile }));
return;
}
this.mobileOpts.push(mobile);
},
removeMobile(mobile) {
const idx = this.mobileOpts.indexOf(mobile);
if (idx > -1) {
this.mobileOpts.splice(idx, 1);
}
},
addUser(userId) {
const trimmedUserId = userId.trim();
const userIdRegex = /^[a-zA-Z0-9]+$/;
if (!userIdRegex.test(trimmedUserId)) {
this.$root.toastError(this.$t("Invalid userId", { "userId": trimmedUserId }));
return;
}
this.userIdOpts.push(trimmedUserId);
},
removeUser(userId) {
const idx = this.userIdOpts.indexOf(userId);
if (idx > -1) {
this.userIdOpts.splice(idx, 1);
}
},
}
};
</script>

View file

@ -690,6 +690,14 @@
"Mentioning": "Mentioning",
"Don't mention people": "Don't mention people",
"Mention group": "Mention {group}",
"Mention Mobile List": "Mention mobile list",
"Mention User List": "Mention user id list",
"Dingtalk Mobile List": "Mobile list",
"Dingtalk User List": "User ID list",
"Enter a list of userId": "Enter a list of userId",
"Enter a list of mobile": "Enter a list of mobile",
"Invalid mobile": "Invalid mobile [{mobile}]",
"Invalid userId": "Invalid userId [{userId}]",
"Device Token": "Device Token",
"Platform": "Platform",
"Huawei": "Huawei",