Commit 1dffb77eb6cee716b490b94e15ad92f9a0a81a87

Authored by fengwotao
1 parent 7061943d

fix: 新增腾讯云短信配置

... ... @@ -55,10 +55,18 @@
55 55 const { createMessage } = useMessage();
56 56 let config = {};
57 57 if (values.messageType === 'PHONE_MESSAGE') {
58   - config = {
59   - accessKeyId: values.accessKeyId,
60   - accessKeySecret: values.accessKeySecret,
61   - };
  58 + if (values.platformType === 'ALI_CLOUD') {
  59 + config = {
  60 + accessKeyId: values.accessKeyId,
  61 + accessKeySecret: values.accessKeySecret,
  62 + };
  63 + } else {
  64 + config = {
  65 + appId: values.appId,
  66 + secretId: values.secretId,
  67 + secretKey: values.secretKey,
  68 + };
  69 + }
62 70 } else if (values.messageType === 'EMAIL_MESSAGE') {
63 71 config = {
64 72 host: values.host,
... ...
... ... @@ -79,6 +79,9 @@ export const isMessage = (type: string) => {
79 79 export const isEmail = (type: string) => {
80 80 return type === MessageEnum.IS_EMAIL;
81 81 };
  82 +export const messageTypeIsTencentCloud = (type: string) => {
  83 + return type === 'TENCENT_CLOUD';
  84 +};
82 85
83 86 export const formSchema: FormSchema[] = [
84 87 {
... ... @@ -121,15 +124,53 @@ export const formSchema: FormSchema[] = [
121 124 ifShow: ({ values }) => isMessage(Reflect.get(values, 'messageType')),
122 125 },
123 126 {
  127 + field: 'appId',
  128 + label: 'appId',
  129 + required: true,
  130 + component: 'Input',
  131 + componentProps: {
  132 + maxLength: 36,
  133 + placeholder: '请输入appId',
  134 + },
  135 + ifShow: ({ values }) => messageTypeIsTencentCloud(Reflect.get(values, 'platformType')),
  136 + },
  137 + {
  138 + field: 'secretId',
  139 + label: 'secretId',
  140 + required: true,
  141 + component: 'Input',
  142 + helpMessage: ['腾讯云:API密钥参考地址: https://console.cloud.tencent.com/cam/capi'],
  143 + componentProps: {
  144 + maxLength: 36,
  145 + placeholder: '请输入secretId',
  146 + },
  147 + ifShow: ({ values }) => messageTypeIsTencentCloud(Reflect.get(values, 'platformType')),
  148 + },
  149 + {
  150 + field: 'secretKey',
  151 + label: 'secretKey',
  152 + required: true,
  153 + componentProps: {
  154 + maxLength: 36,
  155 + placeholder: '请输入secretKey',
  156 + },
  157 +
  158 + component: 'Input',
  159 + ifShow: ({ values }) => messageTypeIsTencentCloud(Reflect.get(values, 'platformType')),
  160 + },
  161 + {
124 162 field: 'accessKeyId',
125 163 label: 'accessKeyId',
126 164 required: true,
127 165 component: 'Input',
  166 + helpMessage: ['阿里云:API密钥参考地址:https://ram.console.aliyun.com/manage/ak'],
128 167 componentProps: {
129 168 maxLength: 36,
130 169 placeholder: '请输入accessKeyId',
131 170 },
132   - ifShow: ({ values }) => isMessage(Reflect.get(values, 'messageType')),
  171 + ifShow: ({ values }) =>
  172 + isMessage(Reflect.get(values, 'messageType')) &&
  173 + !messageTypeIsTencentCloud(Reflect.get(values, 'platformType')),
133 174 },
134 175 {
135 176 field: 'accessKeySecret',
... ... @@ -141,7 +182,9 @@ export const formSchema: FormSchema[] = [
141 182 },
142 183
143 184 component: 'Input',
144   - ifShow: ({ values }) => isMessage(Reflect.get(values, 'messageType')),
  185 + ifShow: ({ values }) =>
  186 + isMessage(Reflect.get(values, 'messageType')) &&
  187 + !messageTypeIsTencentCloud(Reflect.get(values, 'platformType')),
145 188 },
146 189 {
147 190 field: 'host',
... ...
... ... @@ -6,7 +6,7 @@
6 6 </BasicModal>
7 7 </template>
8 8 <script lang="ts">
9   - import { defineComponent } from 'vue';
  9 + import { defineComponent, ref } from 'vue';
10 10 import { BasicModal, useModalInner } from '/@/components/Modal';
11 11 import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
12 12 import { sendSms } from '/@/api/message/template';
... ... @@ -76,7 +76,7 @@
76 76 label: '短信参数',
77 77 required: true,
78 78 componentProps: {
79   - placeholder: '示例:{"code":"3654"}',
  79 + placeholder: '示例:{"code":"1234"}',
80 80 },
81 81 dynamicRules: () => {
82 82 return [
... ... @@ -90,10 +90,10 @@
90 90 if (typeof JSON.parse(value) == 'object') {
91 91 return Promise.resolve();
92 92 }
93   - return Promise.reject('请输入JSON格式例如{"code":"123"}');
  93 + return Promise.reject('请输入JSON格式例如{"code":"1234"}');
94 94 }
95 95 } catch {
96   - return Promise.reject('请输入JSON格式例如{"code":"123"}');
  96 + return Promise.reject('请输入JSON格式例如{"code":"1234"}');
97 97 }
98 98 },
99 99 },
... ... @@ -126,8 +126,9 @@
126 126 export default defineComponent({
127 127 components: { BasicModal, BasicForm },
128 128 setup() {
  129 + const platformType = ref('');
129 130 const { createMessage } = useMessage();
130   - const [registerForm, { validate, resetFields, setFieldsValue }] = useForm({
  131 + const [registerForm, { validate, resetFields, setFieldsValue, updateSchema }] = useForm({
131 132 labelWidth: 70,
132 133 schemas,
133 134 showActionButtonGroup: false,
... ... @@ -136,6 +137,14 @@
136 137 },
137 138 });
138 139 const [register, { closeModal }] = useModalInner(async (data) => {
  140 + platformType.value = data.record?.messageConfig?.platformType;
  141 + updateSchema({
  142 + field: 'params',
  143 + componentProps: {
  144 + placeholder:
  145 + platformType.value !== 'TENCENT_CLOUD' ? '示例:{"code":"1234"}' : '示例:["123456"]',
  146 + },
  147 + });
139 148 await resetFields();
140 149 await setFieldsValue({
141 150 ...data.record,
... ... @@ -143,9 +152,17 @@
143 152 });
144 153
145 154 async function handleOK() {
  155 + let smsParams: any = null;
146 156 const values = await validate();
147   - //将字符串转为json
148   - const smsParams = JSON.parse(Reflect.get(values, 'params'));
  157 + if (platformType.value === 'TENCENT_CLOUD') {
  158 + //腾讯云发送格式 将字符串转为数组
  159 + smsParams = {
  160 + tencent_param: JSON.parse(Reflect.get(values, 'params')),
  161 + };
  162 + } else {
  163 + //阿里云发送格式 将字符串转为json
  164 + smsParams = JSON.parse(Reflect.get(values, 'params'));
  165 + }
149 166 Reflect.set(values, 'params', smsParams);
150 167 await sendSms(values);
151 168 closeModal();
... ...