ny
23 小时以前 282fbc6488f4e8ceb5fda759f963ee88fbf7b999
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<script lang="ts" setup>
import type { FormSchema } from '@jnpf/ui/form';
 
import { computed, reactive } from 'vue';
 
import { useMessage } from '@jnpf/hooks';
import { BasicForm, useForm } from '@jnpf/ui/form';
import { BasicModal, useModalInner } from '@jnpf/ui/modal';
import { formValidate } from '@jnpf/utils';
 
import { create, getInfo, update } from '#/api/msgCenter/accountConfig';
import { $t } from '#/locales';
 
interface State {
  dataForm: any;
}
 
const emit = defineEmits(['register', 'reload']);
const state = reactive<State>({
  dataForm: {},
});
const schemas: FormSchema[] = [
  {
    field: 'fullName',
    label: '名称',
    component: 'Input',
    componentProps: { placeholder: '请输入', maxlength: 50 },
    rules: [{ required: true, trigger: 'blur', message: '必填' }],
  },
  {
    field: 'enCode',
    label: '编码',
    component: 'Input',
    componentProps: { placeholder: '请输入', maxlength: 50 },
    rules: [
      { required: true, trigger: 'blur', message: '必填' },
      { validator: formValidate('enCode'), trigger: 'blur' },
    ],
  },
  {
    field: 'channel',
    label: '渠道',
    component: 'Select',
    defaultValue: 1,
    componentProps: {
      placeholder: '请选择',
      options: [
        { fullName: '阿里云', id: 1 },
        { fullName: '腾讯云', id: 2 },
      ],
      onChange: onChannelChange,
    },
    rules: [{ required: true, trigger: 'change', message: '必填', type: 'number' }],
  },
  {
    field: 'smsSignature',
    label: '短信签名',
    component: 'Input',
    helpMessage: '选择国内消息或国际/港澳台消息,在“签名管理”⻚中获取',
    componentProps: { placeholder: '请输入' },
    rules: [{ required: true, trigger: 'blur', message: '必填' }],
  },
  {
    ifShow: ({ values }) => values.channel === 1,
    field: 'appId',
    label: 'AccessKey ID',
    component: 'Input',
    helpMessage: '请在“阿里云的AccessKey管理-安全信息管理”页中获得',
    componentProps: { placeholder: '请输入' },
    rules: [{ required: true, trigger: 'blur', message: '必填' }],
  },
  {
    ifShow: ({ values }) => values.channel === 1,
    field: 'appSecret',
    label: 'AccessKey Secret',
    component: 'InputPassword',
    helpMessage: '请在“阿里云的AccessKey管理-安全信息管理”页中获得',
    componentProps: { placeholder: '请输入' },
    rules: [{ required: true, trigger: 'blur', message: '必填' }],
  },
  {
    ifShow: ({ values }) => values.channel === 1,
    field: 'endPoint',
    label: 'EndPoint',
    component: 'Input',
    helpMessage: '请在“阿里云的短信服务-OpenAPI Explorer-Region&Endpoint”页中获得',
    componentProps: { placeholder: '请输入' },
    rules: [{ required: true, trigger: 'blur', message: '必填' }],
  },
  {
    ifShow: ({ values }) => values.channel === 2,
    field: 'secretId',
    label: 'SecretId',
    component: 'Input',
    helpMessage: '请在”腾讯云的访问管理-访问密钥- API密钥管理”⻚中获得',
    componentProps: { placeholder: '请输入' },
    rules: [{ required: true, trigger: 'blur', message: '必填' }],
  },
  {
    ifShow: ({ values }) => values.channel === 2,
    field: 'secretKey',
    label: 'SecretKey',
    component: 'InputPassword',
    helpMessage: '请在”腾讯云的访问管理-访问密钥- API密钥管理”⻚中获得',
    componentProps: { placeholder: '请输入' },
    rules: [{ required: true, trigger: 'blur', message: '必填' }],
  },
  {
    ifShow: ({ values }) => values.channel === 2,
    field: 'sdkAppId',
    label: 'SDK AppID',
    component: 'InputPassword',
    helpMessage: '请在”腾讯云的应⽤管理-应⽤列表”⻚中获得',
    componentProps: { placeholder: '请输入' },
    rules: [{ required: true, trigger: 'blur', message: '必填' }],
  },
  {
    ifShow: ({ values }) => values.channel === 2,
    field: 'appKey',
    label: 'App Key',
    component: 'InputPassword',
    helpMessage: '请在”腾讯云的应⽤管理-应⽤列表”⻚中获得',
    componentProps: { placeholder: '请输入' },
    rules: [{ required: true, trigger: 'blur', message: '必填' }],
  },
  {
    ifShow: ({ values }) => values.channel === 2,
    field: 'zoneName',
    label: '地域域名',
    component: 'Input',
    helpMessage: '默认是国内地域域名,也⽀持指定其它地域域名',
    componentProps: { placeholder: '请输入' },
    rules: [{ required: true, trigger: 'blur', message: '必填' }],
  },
  {
    ifShow: ({ values }) => values.channel === 2,
    field: 'zoneParam',
    label: '地域参数',
    component: 'Input',
    helpMessage: '默认是国内地域参数,也⽀持指定其它地域参数',
    componentProps: { placeholder: '请输入' },
    rules: [{ required: true, trigger: 'blur', message: '必填' }],
  },
  {
    field: 'sortCode',
    label: '排序',
    component: 'InputNumber',
    defaultValue: 0,
    componentProps: { min: '0', max: '999999', placeholder: '请输入' },
  },
  {
    field: 'enabledMark',
    label: '状态',
    component: 'Switch',
    defaultValue: 1,
  },
  {
    field: 'description',
    label: '说明',
    component: 'Textarea',
    componentProps: { rows: 3, placeholder: '请输入' },
  },
];
const getTitle = computed(() => (state.dataForm.id ? $t('common.editText') : $t('common.addText')));
const { createMessage } = useMessage();
const [registerForm, { setFieldsValue, validate, resetFields, clearValidate }] = useForm({ labelWidth: 120, schemas });
const [registerModal, { closeModal, changeLoading, changeOkLoading }] = useModalInner(init);
 
function init(data) {
  resetFields();
  state.dataForm.id = data.id;
  if (state.dataForm.id) {
    changeLoading(true);
    getInfo(state.dataForm.id).then((res) => {
      const data = res.data;
      data.secretId = data.channel == 2 ? data.appId : '';
      data.secretKey = data.channel == 2 ? data.appSecret : '';
      state.dataForm = data;
      setFieldsValue(data);
      changeLoading(false);
    });
  }
}
async function handleSubmit() {
  const values = await validate();
  if (!values) return;
  changeOkLoading(true);
  const query = {
    ...values,
    id: state.dataForm.id,
    type: 3,
  };
  if (values.channel === 2) {
    query.appId = values.secretId;
    query.appSecret = values.secretKey;
  }
  const formMethod = state.dataForm.id ? update : create;
  formMethod(query)
    .then((res) => {
      createMessage.success(res.msg);
      changeOkLoading(false);
      closeModal();
      emit('reload');
    })
    .catch(() => {
      changeOkLoading(false);
    });
}
function onChannelChange() {
  setFieldsValue({
    appId: '',
    appSecret: '',
    endPoint: '',
    secretId: '',
    secretKey: '',
    appKey: '',
    sdkAppId: '',
    zoneName: 'sms.tencentcloudapi.com',
    zoneParam: 'ap-beijing',
    smsSignature: '',
  });
  clearValidate();
}
</script>
<template>
  <BasicModal v-bind="$attrs" @register="registerModal" :title="getTitle" show-ok-btn @ok="handleSubmit">
    <BasicForm @register="registerForm" />
  </BasicModal>
</template>