@@ -4,72 +4,50 @@ import { ElMessage, ElLoading } from 'element-plus-secondary'
44import { request } from ' @/utils/request'
55import { useI18n } from ' vue-i18n'
66import type { FormInstance , FormRules } from ' element-plus-secondary'
7+ import { settingMapping } from ' ./common/SettingTemplate'
78const { t } = useI18n ()
89const dialogVisible = ref (false )
910const loadingInstance = ref <ReturnType <typeof ElLoading .service > | null >(null )
10- const wecomForm = ref <FormInstance >()
11- interface WecomkForm {
12- corpid? : string
13- agent_id? : string
14- corpsecret? : string
15- }
11+ const platformForm = ref <FormInstance >()
12+
1613const state = reactive ({
17- form: reactive <WecomkForm >({
18- agent_id: ' ' ,
19- corpid: ' ' ,
20- corpsecret: ' ' ,
21- }),
14+ form: reactive <any >({}),
15+ settingList: [] as any [],
2216})
2317const origin = ref (6 )
2418const id = ref ()
25- const rule = reactive <FormRules >({
26- agent_id: [
27- {
28- required: true ,
29- message: t (' common.require' ),
30- trigger: ' blur' ,
31- },
32- {
33- min: 5 ,
34- max: 20 ,
35- message: t (' common.input_limit' , [5 , 20 ]),
36- trigger: ' blur' ,
37- },
38- ],
39- corpid: [
40- {
41- required: true ,
42- message: t (' common.require' ),
43- trigger: ' blur' ,
44- },
45- {
46- min: 5 ,
47- max: 20 ,
48- message: t (' common.input_limit' , [5 , 20 ]),
49- trigger: ' blur' ,
50- },
51- ],
52- corpsecret: [
53- {
54- required: true ,
55- message: t (' common.require' ),
56- trigger: ' blur' ,
57- },
58- {
59- min: 5 ,
60- max: 100 ,
61- message: t (' common.input_limit' , [5 , 100 ]),
62- trigger: ' blur' ,
63- },
64- ],
65- })
66-
19+ const rule = reactive <FormRules >({})
20+ const formTitle = ref (' ' )
21+ const busiMapping = {
22+ 6 : ' wecom' ,
23+ 7 : ' dingtalk' ,
24+ 8 : ' lark' ,
25+ 9 : ' larksuite' ,
26+ } as any
27+ const initForm = (row : any ) => {
28+ state .settingList .forEach ((item : any ) => {
29+ const key = item .realKey
30+ rule [key ] = [
31+ {
32+ required: true ,
33+ message: t (' common.require' ),
34+ trigger: ' blur' ,
35+ },
36+ {
37+ min: 5 ,
38+ max: 255 ,
39+ message: t (' common.input_limit' , [5 , 255 ]),
40+ trigger: ' blur' ,
41+ },
42+ ]
43+ state .form [key ] = row [key ]
44+ })
45+ }
6746const edit = (row : any ) => {
68- state .form = {
69- agent_id: row .agent_id ,
70- corpid: row .corpid ,
71- corpsecret: row .corpsecret ,
72- }
47+ state .settingList = settingMapping [row .type ]
48+ initForm (row )
49+ origin .value = row .type
50+ formTitle .value = row .title
7351 if (row ?.id ) {
7452 id .value = row .id
7553 }
@@ -86,7 +64,7 @@ const submitForm = async (formEl: FormInstance | undefined) => {
8664 const data = {
8765 id: origin .value ,
8866 type: origin .value ,
89- name: ' wecom ' ,
67+ name: busiMapping [ origin . value ] ,
9068 config: JSON .stringify (param ),
9169 }
9270 const method = id .value
@@ -122,10 +100,15 @@ const resetForm = (formEl: FormInstance | undefined) => {
122100 formEl .resetFields ()
123101 dialogVisible .value = false
124102 id .value = null
103+ origin .value = 6
104+ formTitle .value = ' '
105+ state .settingList = []
106+ const keys = Object .keys (rule )
107+ keys .forEach ((key : string ) => delete rule [key ])
125108}
126109
127110const reset = () => {
128- resetForm (wecomForm .value )
111+ resetForm (platformForm .value )
129112}
130113
131114const showLoading = () => {
@@ -137,28 +120,34 @@ const closeLoading = () => {
137120 loadingInstance .value ?.close ()
138121}
139122
140- const validate = () => {
141- const url = ' /system/authentication/status'
142- const config_data = state .form
143- const data = {
144- type: origin .value ,
145- name: ' wecom' ,
146- config: JSON .stringify (config_data ),
147- }
148- showLoading ()
149- request
150- .patch (url , data )
151- .then ((res ) => {
152- if (res ) {
153- ElMessage .success (t (' ds.connection_success' ))
154- } else {
155- ElMessage .error (t (' ds.connection_failed' ))
156- }
157- })
158- .finally (() => {
159- closeLoading ()
160- emits (' saved' )
161- })
123+ const validate = async (formEl : FormInstance | undefined ) => {
124+ if (! formEl ) return
125+ await formEl .validate ((valid ) => {
126+ if (! valid ) {
127+ return
128+ }
129+ const url = ' /system/authentication/status'
130+ const config_data = state .form
131+ const data = {
132+ type: origin .value ,
133+ name: busiMapping [origin .value ],
134+ config: JSON .stringify (config_data ),
135+ }
136+ showLoading ()
137+ request
138+ .patch (url , data )
139+ .then ((res ) => {
140+ if (res ) {
141+ ElMessage .success (t (' ds.connection_success' ))
142+ } else {
143+ ElMessage .error (t (' ds.connection_failed' ))
144+ }
145+ })
146+ .finally (() => {
147+ closeLoading ()
148+ emits (' saved' )
149+ })
150+ })
162151}
163152
164153defineExpose ({
@@ -169,46 +158,46 @@ defineExpose({
169158<template >
170159 <el-drawer
171160 v-model =" dialogVisible"
172- :title =" t('user.wechat_for_business') "
161+ :title =" formTitle "
173162 modal-class =" platform-info-drawer"
174163 size =" 600px"
175164 direction =" rtl"
176165 >
177166 <el-form
178- ref =" wecomForm "
167+ ref =" platformForm "
179168 require-asterisk-position =" right"
180169 :model =" state.form"
181170 :rules =" rule"
182171 label-width =" 80px"
183172 label-position =" top"
184173 >
185- <el-form-item label =" Corpid" prop =" corpid" >
186- <el-input v-model =" state.form.corpid" :placeholder =" t('common.please_input')" />
187- </el-form-item >
188-
189- <el-form-item label =" AgentId" prop =" agent_id" >
190- <el-input v-model =" state.form.agent_id" :placeholder =" t('common.please_input')" />
191- </el-form-item >
192-
193- <el-form-item label =" APP Secret" prop =" corpsecret" >
174+ <el-form-item
175+ v-for =" setting in state.settingList"
176+ :key =" setting.realKey"
177+ :label =" setting.pkey"
178+ :prop =" setting.realKey"
179+ >
194180 <el-input
195- v-model =" state.form.corpsecret"
181+ v-if =" setting.type === 'password'"
182+ v-model =" state.form[setting.realKey]"
196183 type =" password"
197184 show-password
198185 :placeholder =" t('common.please_input')"
199186 />
187+ <el-input
188+ v-else
189+ v-model =" state.form[setting.realKey]"
190+ :placeholder =" t('common.please_input')"
191+ />
200192 </el-form-item >
201193 </el-form >
202194 <template #footer >
203195 <span class =" dialog-footer" >
204- <el-button @click =" resetForm(wecomForm)" >{{ t('common.cancel') }}</el-button >
205- <el-button
206- :disabled =" !state.form.corpid || !state.form.corpsecret || !state.form.agent_id"
207- @click =" validate"
208- >
196+ <el-button @click =" resetForm(platformForm)" >{{ t('common.cancel') }}</el-button >
197+ <el-button @click =" validate(platformForm)" >
209198 {{ t('ds.check') }}
210199 </el-button >
211- <el-button type =" primary" @click =" submitForm(wecomForm )" >
200+ <el-button type =" primary" @click =" submitForm(platformForm )" >
212201 {{ t('common.save') }}
213202 </el-button >
214203 </span >
0 commit comments