Showing
3 changed files
with
81 additions
and
13 deletions
@@ -55,10 +55,18 @@ | @@ -55,10 +55,18 @@ | ||
55 | const { createMessage } = useMessage(); | 55 | const { createMessage } = useMessage(); |
56 | let config = {}; | 56 | let config = {}; |
57 | if (values.messageType === 'PHONE_MESSAGE') { | 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 | } else if (values.messageType === 'EMAIL_MESSAGE') { | 70 | } else if (values.messageType === 'EMAIL_MESSAGE') { |
63 | config = { | 71 | config = { |
64 | host: values.host, | 72 | host: values.host, |
@@ -79,6 +79,9 @@ export const isMessage = (type: string) => { | @@ -79,6 +79,9 @@ export const isMessage = (type: string) => { | ||
79 | export const isEmail = (type: string) => { | 79 | export const isEmail = (type: string) => { |
80 | return type === MessageEnum.IS_EMAIL; | 80 | return type === MessageEnum.IS_EMAIL; |
81 | }; | 81 | }; |
82 | +export const messageTypeIsTencentCloud = (type: string) => { | ||
83 | + return type === 'TENCENT_CLOUD'; | ||
84 | +}; | ||
82 | 85 | ||
83 | export const formSchema: FormSchema[] = [ | 86 | export const formSchema: FormSchema[] = [ |
84 | { | 87 | { |
@@ -121,15 +124,53 @@ export const formSchema: FormSchema[] = [ | @@ -121,15 +124,53 @@ export const formSchema: FormSchema[] = [ | ||
121 | ifShow: ({ values }) => isMessage(Reflect.get(values, 'messageType')), | 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 | field: 'accessKeyId', | 162 | field: 'accessKeyId', |
125 | label: 'accessKeyId', | 163 | label: 'accessKeyId', |
126 | required: true, | 164 | required: true, |
127 | component: 'Input', | 165 | component: 'Input', |
166 | + helpMessage: ['阿里云:API密钥参考地址:https://ram.console.aliyun.com/manage/ak'], | ||
128 | componentProps: { | 167 | componentProps: { |
129 | maxLength: 36, | 168 | maxLength: 36, |
130 | placeholder: '请输入accessKeyId', | 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 | field: 'accessKeySecret', | 176 | field: 'accessKeySecret', |
@@ -141,7 +182,9 @@ export const formSchema: FormSchema[] = [ | @@ -141,7 +182,9 @@ export const formSchema: FormSchema[] = [ | ||
141 | }, | 182 | }, |
142 | 183 | ||
143 | component: 'Input', | 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 | field: 'host', | 190 | field: 'host', |
@@ -6,7 +6,7 @@ | @@ -6,7 +6,7 @@ | ||
6 | </BasicModal> | 6 | </BasicModal> |
7 | </template> | 7 | </template> |
8 | <script lang="ts"> | 8 | <script lang="ts"> |
9 | - import { defineComponent } from 'vue'; | 9 | + import { defineComponent, ref } from 'vue'; |
10 | import { BasicModal, useModalInner } from '/@/components/Modal'; | 10 | import { BasicModal, useModalInner } from '/@/components/Modal'; |
11 | import { BasicForm, FormSchema, useForm } from '/@/components/Form/index'; | 11 | import { BasicForm, FormSchema, useForm } from '/@/components/Form/index'; |
12 | import { sendSms } from '/@/api/message/template'; | 12 | import { sendSms } from '/@/api/message/template'; |
@@ -76,7 +76,7 @@ | @@ -76,7 +76,7 @@ | ||
76 | label: '短信参数', | 76 | label: '短信参数', |
77 | required: true, | 77 | required: true, |
78 | componentProps: { | 78 | componentProps: { |
79 | - placeholder: '示例:{"code":"3654"}', | 79 | + placeholder: '示例:{"code":"1234"}', |
80 | }, | 80 | }, |
81 | dynamicRules: () => { | 81 | dynamicRules: () => { |
82 | return [ | 82 | return [ |
@@ -90,10 +90,10 @@ | @@ -90,10 +90,10 @@ | ||
90 | if (typeof JSON.parse(value) == 'object') { | 90 | if (typeof JSON.parse(value) == 'object') { |
91 | return Promise.resolve(); | 91 | return Promise.resolve(); |
92 | } | 92 | } |
93 | - return Promise.reject('请输入JSON格式例如{"code":"123"}'); | 93 | + return Promise.reject('请输入JSON格式例如{"code":"1234"}'); |
94 | } | 94 | } |
95 | } catch { | 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,8 +126,9 @@ | ||
126 | export default defineComponent({ | 126 | export default defineComponent({ |
127 | components: { BasicModal, BasicForm }, | 127 | components: { BasicModal, BasicForm }, |
128 | setup() { | 128 | setup() { |
129 | + const platformType = ref(''); | ||
129 | const { createMessage } = useMessage(); | 130 | const { createMessage } = useMessage(); |
130 | - const [registerForm, { validate, resetFields, setFieldsValue }] = useForm({ | 131 | + const [registerForm, { validate, resetFields, setFieldsValue, updateSchema }] = useForm({ |
131 | labelWidth: 70, | 132 | labelWidth: 70, |
132 | schemas, | 133 | schemas, |
133 | showActionButtonGroup: false, | 134 | showActionButtonGroup: false, |
@@ -136,6 +137,14 @@ | @@ -136,6 +137,14 @@ | ||
136 | }, | 137 | }, |
137 | }); | 138 | }); |
138 | const [register, { closeModal }] = useModalInner(async (data) => { | 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 | await resetFields(); | 148 | await resetFields(); |
140 | await setFieldsValue({ | 149 | await setFieldsValue({ |
141 | ...data.record, | 150 | ...data.record, |
@@ -143,9 +152,17 @@ | @@ -143,9 +152,17 @@ | ||
143 | }); | 152 | }); |
144 | 153 | ||
145 | async function handleOK() { | 154 | async function handleOK() { |
155 | + let smsParams: any = null; | ||
146 | const values = await validate(); | 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 | Reflect.set(values, 'params', smsParams); | 166 | Reflect.set(values, 'params', smsParams); |
150 | await sendSms(values); | 167 | await sendSms(values); |
151 | closeModal(); | 168 | closeModal(); |