|
42 | 42 | <AuthButton |
43 | 43 | action-id="biz_notify_config" |
44 | 44 | class="w-88" |
| 45 | + :disabled="resetSettingLoading" |
45 | 46 | :loading="updateSettingLoading" |
46 | 47 | :resource="bizId" |
47 | 48 | theme="primary" |
48 | | - @click="handleSubmit"> |
49 | | - {{ t('提交') }} |
| 49 | + @click="handleSave"> |
| 50 | + {{ t('保存') }} |
50 | 51 | </AuthButton> |
51 | | - <BkButton |
52 | | - class="ml8 w-88" |
53 | | - :disabled="updateSettingLoading" |
54 | | - @click="handleReset"> |
55 | | - {{ t('重置') }} |
56 | | - </BkButton> |
| 52 | + <DbPopconfirm |
| 53 | + ref="dbPopconfirm" |
| 54 | + :confirm-handler="handleReset" |
| 55 | + :content="t('重置将会恢复默认设置的内容')" |
| 56 | + :title="t('确认重置')"> |
| 57 | + <AuthButton |
| 58 | + v-model:is-auth="isAuth" |
| 59 | + action-id="biz_notify_config" |
| 60 | + class="ml8 w-88" |
| 61 | + :disabled="updateSettingLoading" |
| 62 | + :loading="resetSettingLoading" |
| 63 | + :resource="bizId"> |
| 64 | + {{ t('重置') }} |
| 65 | + </AuthButton> |
| 66 | + </DbPopconfirm> |
57 | 67 | </template> |
58 | 68 | </SmartAction> |
59 | 69 | </BkLoading> |
|
67 | 77 | import { getBizSettingList, updateBizSetting } from '@services/source/bizSetting'; |
68 | 78 | import { getAlarmGroupNotifyList } from '@services/source/monitorNoticeGroup'; |
69 | 79 |
|
70 | | - import { InputMessageTypes, MessageTypes } from '@common/const' |
| 80 | + import { InputMessageTypes, MessageTipMap, MessageTypes } from '@common/const' |
71 | 81 |
|
72 | 82 | import { messageSuccess } from '@utils'; |
73 | 83 |
|
| 84 | + type AlarmGroupNotify = ServiceReturnType<typeof getAlarmGroupNotifyList> |
| 85 | + type TicketNoticeSetting = Record<string, Record<string, boolean | string[]>> |
| 86 | +
|
74 | 87 | interface DataRow { |
75 | 88 | status: string; |
76 | 89 | statusText: string; |
|
81 | 94 |
|
82 | 95 | const { t } = useI18n(); |
83 | 96 |
|
| 97 | + const dbPopconfirmRef = useTemplateRef('dbPopconfirm') |
| 98 | +
|
84 | 99 | const dataList = ref<DataRow[]>([]); |
| 100 | + const isAuth = ref(false); |
85 | 101 |
|
86 | 102 | const bizId = window.PROJECT_CONFIG.BIZ_ID |
| 103 | + const DefaultMessageTypeList = [MessageTypes.MAIL, MessageTypes.RTX] |
| 104 | + const NoticeTicketTypeList = Object.entries(TicketModel.statusTextMap).filter(([status]) => ![TicketModel.STATUS_RUNNING, TicketModel.STATUS_TIMER].includes(status)) |
87 | 105 |
|
88 | 106 | const columns = computed(() => { |
89 | 107 | const baseColumns = [ |
|
100 | 118 | }, |
101 | 119 | ]; |
102 | 120 |
|
103 | | - const nofityColumns = (alarmGroupNotifyList.value || []).filter((item) => item.is_active).map(item => { |
| 121 | + // input 类型的放最后 |
| 122 | + const activeTypeMap = (alarmGroupNotifyList.value || []).reduce<{ |
| 123 | + checkbox: AlarmGroupNotify, |
| 124 | + input: AlarmGroupNotify, |
| 125 | + }>((prevMap, item) => { |
| 126 | + if (item.is_active) { |
| 127 | + if (InputMessageTypes.includes(item.type)) { |
| 128 | + Object.assign(prevMap.input, prevMap.input.concat(item)) |
| 129 | + } else { |
| 130 | + Object.assign(prevMap.checkbox, prevMap.checkbox.concat(item)) |
| 131 | + } |
| 132 | + } |
| 133 | + return prevMap; |
| 134 | + }, { |
| 135 | + checkbox: [], |
| 136 | + input: [] |
| 137 | + }) |
| 138 | +
|
| 139 | + const nofityColumns = [...activeTypeMap.checkbox, ...activeTypeMap.input].map(item => { |
104 | 140 | const isInputType = InputMessageTypes.includes(item.type) |
| 141 | + const messageTip = MessageTipMap[item.type] |
105 | 142 | return { |
106 | 143 | field: item.type, |
107 | 144 | minWidth: isInputType ? 320 : 120, |
|
116 | 153 | class="ml-4"> |
117 | 154 | { item.label } |
118 | 155 | </span> |
| 156 | + { |
| 157 | + messageTip && ( |
| 158 | + <db-icon |
| 159 | + class="message-type-head-tip ml-4" |
| 160 | + v-bk-tooltips={{ |
| 161 | + content: messageTip |
| 162 | + }} |
| 163 | + type="attention" /> |
| 164 | + ) |
| 165 | + } |
119 | 166 | </div> |
120 | 167 | ), |
121 | 168 | render: ({ data } : { data: DataRow }) => { |
|
146 | 193 | manual: true, |
147 | 194 | onSuccess: () => { |
148 | 195 | messageSuccess(t('保存成功')); |
| 196 | + getData() |
| 197 | + }, |
| 198 | + }); |
| 199 | +
|
| 200 | + const { loading: resetSettingLoading, run: runResetBizSetting } = useRequest(updateBizSetting, { |
| 201 | + manual: true, |
| 202 | + onSuccess: () => { |
| 203 | + messageSuccess(t('重置成功')); |
| 204 | + getData() |
149 | 205 | }, |
150 | 206 | }); |
151 | 207 |
|
| 208 | + watch(isAuth, () => { |
| 209 | + if (isAuth.value) { |
| 210 | + dbPopconfirmRef.value?.updateTriggerTarget() |
| 211 | + } |
| 212 | + }) |
| 213 | +
|
152 | 214 | watch([bizSetting, alarmGroupNotifyList], () => { |
153 | 215 | if (bizSetting.value && alarmGroupNotifyList.value) { |
154 | 216 | const activeTypeMap = alarmGroupNotifyList.value.reduce<{ |
|
175 | 237 | const isBizSettingEmpty = _.isEmpty(bizSetting.value) || _.isEmpty(bizSetting.value.NOTIFY_CONFIG) |
176 | 238 | const list: DataRow[] = [] |
177 | 239 |
|
178 | | - Object.entries(TicketModel.statusTextMap).forEach(([status, statusText]) => { |
179 | | - if (![TicketModel.STATUS_RUNNING, TicketModel.STATUS_TIMER].includes(status)) { |
180 | | - const initSetting = _.cloneDeep(activeTypeMap) |
181 | | - if (isBizSettingEmpty) { |
182 | | - [MessageTypes.MAIL, MessageTypes.RTX].forEach(type => { |
183 | | - if (initSetting.checkbox[type] !== undefined) { |
184 | | - initSetting.checkbox[type] = true; |
185 | | - } |
186 | | - }); |
187 | | - } else { |
188 | | - const statusBizSetting = bizSetting.value!.NOTIFY_CONFIG[status] |
189 | | - Object.keys(initSetting.checkbox).forEach(initSettingKey => { |
190 | | - initSetting.checkbox[initSettingKey] = statusBizSetting[initSettingKey] || false |
191 | | - }) |
192 | | - Object.keys(initSetting.input).forEach(initSettingKey => { |
193 | | - initSetting.input[initSettingKey] = (statusBizSetting[initSettingKey] || []).join(',') |
194 | | - }) |
195 | | - } |
196 | | -
|
197 | | - list.push({ |
198 | | - status, |
199 | | - statusText, |
200 | | - noticeMember: status === TicketModel.STATUS_APPROVE ? [t('审批人')] : [t('提单人'), t('协助人')], |
201 | | - checkbox: initSetting.checkbox, |
202 | | - input: initSetting.input |
| 240 | + NoticeTicketTypeList.forEach(([status, statusText]) => { |
| 241 | + const initSetting = _.cloneDeep(activeTypeMap) |
| 242 | + if (isBizSettingEmpty) { |
| 243 | + DefaultMessageTypeList.forEach(type => { |
| 244 | + if (initSetting.checkbox[type] !== undefined) { |
| 245 | + initSetting.checkbox[type] = true; |
| 246 | + } |
| 247 | + }); |
| 248 | + } else { |
| 249 | + const statusBizSetting = bizSetting.value!.NOTIFY_CONFIG[status] |
| 250 | + Object.keys(initSetting.checkbox).forEach(initSettingKey => { |
| 251 | + initSetting.checkbox[initSettingKey] = statusBizSetting[initSettingKey] || false |
| 252 | + }) |
| 253 | + Object.keys(initSetting.input).forEach(initSettingKey => { |
| 254 | + initSetting.input[initSettingKey] = (statusBizSetting[initSettingKey] || []).join(',') |
203 | 255 | }) |
204 | 256 | } |
| 257 | +
|
| 258 | + list.push({ |
| 259 | + status, |
| 260 | + statusText, |
| 261 | + noticeMember: status === TicketModel.STATUS_APPROVE ? [t('审批人')] : [t('提单人'), t('协助人')], |
| 262 | + checkbox: initSetting.checkbox, |
| 263 | + input: initSetting.input |
| 264 | + }) |
205 | 265 | }) |
206 | 266 | dataList.value = list |
207 | 267 | } |
|
221 | 281 | }) |
222 | 282 | } |
223 | 283 |
|
224 | | - const handleSubmit = () => { |
| 284 | + const handleSave = () => { |
225 | 285 | runUpdateBizSetting({ |
226 | 286 | bk_biz_id: bizId, |
227 | 287 | key: 'NOTIFY_CONFIG', |
228 | | - value: dataList.value.reduce<Record<string, Record<string, boolean | string[]>>>((prevMap, dataItem) => { |
| 288 | + value: dataList.value.reduce<TicketNoticeSetting>((prevMap, dataItem) => { |
229 | 289 | const checkboxMap = Object.entries(dataItem.checkbox).reduce<Record<string, boolean>>((prevMap, [key, value])=> { |
230 | 290 | if (value) { |
231 | 291 | return Object.assign({}, prevMap, { [key]: value }) |
|
249 | 309 | }; |
250 | 310 |
|
251 | 311 | const handleReset = () => { |
252 | | - getData() |
| 312 | + runResetBizSetting({ |
| 313 | + bk_biz_id: bizId, |
| 314 | + key: 'NOTIFY_CONFIG', |
| 315 | + value: NoticeTicketTypeList.reduce<TicketNoticeSetting>((prevSettingMap, [status]) => Object.assign({}, prevSettingMap, { |
| 316 | + [status]: DefaultMessageTypeList.reduce<Record<string, boolean>>((prevValueMap, type) => Object.assign({}, prevValueMap, { |
| 317 | + [type]: true |
| 318 | + }), {}) |
| 319 | + }), {}) |
| 320 | + }) |
253 | 321 | }; |
254 | 322 |
|
255 | 323 | // 初始化查询 |
|
283 | 351 | .message-type-head { |
284 | 352 | display: flex; |
285 | 353 | align-items: center; |
| 354 | +
|
| 355 | + .message-type-head-tip { |
| 356 | + font-size: 14px; |
| 357 | + color: #63656e; |
| 358 | + } |
286 | 359 | } |
287 | 360 | } |
288 | 361 | } |
|
0 commit comments