Commit 40c29078feb19b2daa5b86e572049fca2f103318
Merge branch 'fix/public-interface' into 'main_dev'
fix: 修复大屏设计公共接口创建时根据当前角色设置默认接口类型 See merge request yunteng/thingskit-front!722
Showing
2 changed files
with
174 additions
and
181 deletions
1 | 1 | import { BasicColumn, FormSchema } from '/@/components/Table'; |
2 | -import { h } from 'vue'; | |
2 | +import { h, unref } from 'vue'; | |
3 | 3 | import { Tag } from 'ant-design-vue'; |
4 | 4 | import { findDictItemByCode } from '/@/api/system/dict'; |
5 | 5 | import { USER_INFO_KEY } from '/@/enums/cacheEnum'; |
... | ... | @@ -7,6 +7,7 @@ import { getAuthCache } from '/@/utils/auth'; |
7 | 7 | import { isAdmin } from '/@/enums/roleEnum'; |
8 | 8 | import { defaultField } from './constants'; |
9 | 9 | import { useUtils } from '../hooks/useUtils'; |
10 | +import { useRole } from '/@/hooks/business/useRole'; | |
10 | 11 | |
11 | 12 | // 表格配置 |
12 | 13 | export const columns: BasicColumn[] = [ |
... | ... | @@ -106,189 +107,192 @@ export const searchFormSchema: FormSchema[] = [ |
106 | 107 | ]; |
107 | 108 | |
108 | 109 | //表单配置 |
109 | -export const schemas: FormSchema[] = [ | |
110 | - { | |
111 | - field: 'interfaceName', | |
112 | - label: '接口名称', | |
113 | - colProps: { span: 24 }, | |
114 | - required: true, | |
115 | - component: 'Input', | |
116 | - componentProps: { | |
117 | - maxLength: 255, | |
118 | - placeholder: '请输入接口名称', | |
119 | - }, | |
120 | - }, | |
121 | - { | |
122 | - field: 'interfaceType', | |
123 | - component: 'ApiRadioGroup', | |
124 | - label: '接口类型', | |
125 | - required: true, | |
126 | - colProps: { | |
127 | - span: 8, | |
128 | - }, | |
129 | - defaultValue: 'SYSTEM', | |
130 | - componentProps: { | |
131 | - api: findDictItemByCode, | |
132 | - params: { | |
133 | - dictCode: 'interface_Type', | |
110 | +export const schemas = (): FormSchema[] => { | |
111 | + const { isPlatformAdmin, isSysadmin } = useRole(); | |
112 | + return [ | |
113 | + { | |
114 | + field: 'interfaceName', | |
115 | + label: '接口名称', | |
116 | + colProps: { span: 24 }, | |
117 | + required: true, | |
118 | + component: 'Input', | |
119 | + componentProps: { | |
120 | + maxLength: 255, | |
121 | + placeholder: '请输入接口名称', | |
134 | 122 | }, |
135 | - labelField: 'itemText', | |
136 | - valueField: 'itemValue', | |
137 | - }, | |
138 | - ifShow: ({}) => { | |
139 | - const userInfo = getAuthCache(USER_INFO_KEY) as any; | |
140 | - const role: string = userInfo?.roles[0]; | |
141 | - if (isAdmin(role)) return true; | |
142 | - else return false; | |
143 | 123 | }, |
144 | - }, | |
145 | - { | |
146 | - field: 'requestContentType', | |
147 | - label: '请求方式', | |
148 | - component: 'ApiSelect', | |
149 | - required: true, | |
150 | - colProps: { span: 24 }, | |
151 | - defaultValue: '0', | |
152 | - componentProps: ({ formActionType }) => { | |
153 | - const { updateSchema, setFieldsValue } = formActionType; | |
154 | - return { | |
124 | + { | |
125 | + field: 'interfaceType', | |
126 | + component: 'ApiRadioGroup', | |
127 | + label: '接口类型', | |
128 | + required: true, | |
129 | + colProps: { | |
130 | + span: 8, | |
131 | + }, | |
132 | + defaultValue: unref(isPlatformAdmin) || unref(isSysadmin) ? 'SYSTEM' : null, | |
133 | + componentProps: { | |
155 | 134 | api: findDictItemByCode, |
156 | 135 | params: { |
157 | - dictCode: 'dataview_select_methods', | |
136 | + dictCode: 'interface_Type', | |
158 | 137 | }, |
159 | - placeholder: '请选择请求方式', | |
160 | 138 | labelField: 'itemText', |
161 | 139 | valueField: 'itemValue', |
162 | - getPopupContainer: () => document.body, | |
163 | - onChange(e) { | |
164 | - if (!e) return; | |
165 | - const { usePlaceholder } = useUtils(); | |
166 | - const setDefaultPlaceholder = usePlaceholder(e); | |
167 | - setFieldsValue(defaultField); | |
168 | - updateSchema({ | |
169 | - field: 'requestHttpTypeAndUrl', | |
170 | - componentProps: { | |
171 | - type: e, | |
172 | - }, | |
173 | - }); | |
174 | - updateSchema({ | |
175 | - field: 'requestOriginUrl', | |
176 | - componentProps: { | |
177 | - placeholder: setDefaultPlaceholder, | |
178 | - }, | |
179 | - }); | |
180 | - }, | |
181 | - }; | |
140 | + }, | |
141 | + ifShow: ({}) => { | |
142 | + const userInfo = getAuthCache(USER_INFO_KEY) as any; | |
143 | + const role: string = userInfo?.roles[0]; | |
144 | + if (isAdmin(role)) return true; | |
145 | + else return false; | |
146 | + }, | |
182 | 147 | }, |
183 | - }, | |
184 | - { | |
185 | - field: 'originUrlType', | |
186 | - label: '地址类型', | |
187 | - component: 'ApiSelect', | |
188 | - required: true, | |
189 | - colProps: { span: 24 }, | |
190 | - defaultValue: 'server_url', | |
191 | - componentProps: ({ formActionType }) => { | |
192 | - const { setFieldsValue } = formActionType; | |
193 | - return { | |
194 | - placeholder: '请选择地址类型', | |
195 | - api: findDictItemByCode, | |
196 | - params: { | |
197 | - dictCode: 'dataview_select_origin_type', | |
198 | - }, | |
199 | - labelField: 'itemText', | |
200 | - valueField: 'itemValue', | |
201 | - onChange: (e) => { | |
202 | - if (!e) return; | |
203 | - setFieldsValue({ | |
204 | - requestOriginUrl: '', | |
205 | - }); | |
206 | - }, | |
207 | - }; | |
148 | + { | |
149 | + field: 'requestContentType', | |
150 | + label: '请求方式', | |
151 | + component: 'ApiSelect', | |
152 | + required: true, | |
153 | + colProps: { span: 24 }, | |
154 | + defaultValue: '0', | |
155 | + componentProps: ({ formActionType }) => { | |
156 | + const { updateSchema, setFieldsValue } = formActionType; | |
157 | + return { | |
158 | + api: findDictItemByCode, | |
159 | + params: { | |
160 | + dictCode: 'dataview_select_methods', | |
161 | + }, | |
162 | + placeholder: '请选择请求方式', | |
163 | + labelField: 'itemText', | |
164 | + valueField: 'itemValue', | |
165 | + getPopupContainer: () => document.body, | |
166 | + onChange(e) { | |
167 | + if (!e) return; | |
168 | + const { usePlaceholder } = useUtils(); | |
169 | + const setDefaultPlaceholder = usePlaceholder(e); | |
170 | + setFieldsValue(defaultField); | |
171 | + updateSchema({ | |
172 | + field: 'requestHttpTypeAndUrl', | |
173 | + componentProps: { | |
174 | + type: e, | |
175 | + }, | |
176 | + }); | |
177 | + updateSchema({ | |
178 | + field: 'requestOriginUrl', | |
179 | + componentProps: { | |
180 | + placeholder: setDefaultPlaceholder, | |
181 | + }, | |
182 | + }); | |
183 | + }, | |
184 | + }; | |
185 | + }, | |
208 | 186 | }, |
209 | - }, | |
210 | - { | |
211 | - field: 'requestOriginUrl', | |
212 | - label: '源地址', | |
213 | - colProps: { span: 24 }, | |
214 | - required: true, | |
215 | - component: 'Input', | |
216 | - componentProps: ({ formActionType }) => { | |
217 | - const { getFieldsValue } = formActionType; | |
218 | - const type = getFieldsValue()?.requestContentType; | |
219 | - const { usePlaceholder } = useUtils(); | |
220 | - return { | |
221 | - placeholder: usePlaceholder(type), | |
222 | - }; | |
187 | + { | |
188 | + field: 'originUrlType', | |
189 | + label: '地址类型', | |
190 | + component: 'ApiSelect', | |
191 | + required: true, | |
192 | + colProps: { span: 24 }, | |
193 | + defaultValue: 'server_url', | |
194 | + componentProps: ({ formActionType }) => { | |
195 | + const { setFieldsValue } = formActionType; | |
196 | + return { | |
197 | + placeholder: '请选择地址类型', | |
198 | + api: findDictItemByCode, | |
199 | + params: { | |
200 | + dictCode: 'dataview_select_origin_type', | |
201 | + }, | |
202 | + labelField: 'itemText', | |
203 | + valueField: 'itemValue', | |
204 | + onChange: (e) => { | |
205 | + if (!e) return; | |
206 | + setFieldsValue({ | |
207 | + requestOriginUrl: '', | |
208 | + }); | |
209 | + }, | |
210 | + }; | |
211 | + }, | |
223 | 212 | }, |
224 | - ifShow: ({ values }) => values['originUrlType'] === 'custom_url', | |
225 | - }, | |
226 | - { | |
227 | - field: 'requestHttpTypeAndUrl', | |
228 | - label: '请求类型&地址', | |
229 | - component: 'InputGroup', | |
230 | - required: true, | |
231 | - colProps: { span: 24 }, | |
232 | - componentProps: ({ formActionType }) => { | |
233 | - const { getFieldsValue } = formActionType; | |
234 | - return { | |
235 | - type: getFieldsValue().requestContentType, | |
236 | - }; | |
213 | + { | |
214 | + field: 'requestOriginUrl', | |
215 | + label: '源地址', | |
216 | + colProps: { span: 24 }, | |
217 | + required: true, | |
218 | + component: 'Input', | |
219 | + componentProps: ({ formActionType }) => { | |
220 | + const { getFieldsValue } = formActionType; | |
221 | + const type = getFieldsValue()?.requestContentType; | |
222 | + const { usePlaceholder } = useUtils(); | |
223 | + return { | |
224 | + placeholder: usePlaceholder(type), | |
225 | + }; | |
226 | + }, | |
227 | + ifShow: ({ values }) => values['originUrlType'] === 'custom_url', | |
237 | 228 | }, |
238 | - }, | |
239 | - { | |
240 | - field: 'fillAddress', | |
241 | - label: '完整地址', | |
242 | - component: 'Input', | |
243 | - slot: 'slotFillAddress', | |
244 | - colProps: { span: 24 }, | |
245 | - ifShow: ({ values }) => { | |
246 | - return values['originUrlType'] === 'custom_url' && values['requestOriginUrl']; | |
229 | + { | |
230 | + field: 'requestHttpTypeAndUrl', | |
231 | + label: '请求类型&地址', | |
232 | + component: 'InputGroup', | |
233 | + required: true, | |
234 | + colProps: { span: 24 }, | |
235 | + componentProps: ({ formActionType }) => { | |
236 | + const { getFieldsValue } = formActionType; | |
237 | + return { | |
238 | + type: getFieldsValue().requestContentType, | |
239 | + }; | |
240 | + }, | |
247 | 241 | }, |
248 | - }, | |
249 | - { | |
250 | - field: 'slotServerAddress', | |
251 | - label: '完整地址', | |
252 | - component: 'Input', | |
253 | - slot: 'slotServerAddress', | |
254 | - colProps: { span: 24 }, | |
255 | - ifShow: ({ values }) => { | |
256 | - return values['originUrlType'] === 'server_url'; | |
242 | + { | |
243 | + field: 'fillAddress', | |
244 | + label: '完整地址', | |
245 | + component: 'Input', | |
246 | + slot: 'slotFillAddress', | |
247 | + colProps: { span: 24 }, | |
248 | + ifShow: ({ values }) => { | |
249 | + return values['originUrlType'] === 'custom_url' && values['requestOriginUrl']; | |
250 | + }, | |
257 | 251 | }, |
258 | - }, | |
259 | - { | |
260 | - field: 'requestSQLKey', | |
261 | - label: '键名', | |
262 | - colProps: { span: 6 }, | |
263 | - component: 'Input', | |
264 | - defaultValue: 'sql', | |
265 | - componentProps: { | |
266 | - disabled: true, | |
252 | + { | |
253 | + field: 'slotServerAddress', | |
254 | + label: '完整地址', | |
255 | + component: 'Input', | |
256 | + slot: 'slotServerAddress', | |
257 | + colProps: { span: 24 }, | |
258 | + ifShow: ({ values }) => { | |
259 | + return values['originUrlType'] === 'server_url'; | |
260 | + }, | |
267 | 261 | }, |
268 | - ifShow: ({ values }) => values['requestContentType'] === '1', | |
269 | - }, | |
270 | - { | |
271 | - field: 'requestSQLContent', | |
272 | - label: '键值', | |
273 | - colProps: { span: 24 }, | |
274 | - component: 'InputTextArea', | |
275 | - defaultValue: 'select * from where', | |
276 | - componentProps: { | |
277 | - maxLength: 255, | |
278 | - placeholder: '请输入键值', | |
279 | - rows: 6, | |
262 | + { | |
263 | + field: 'requestSQLKey', | |
264 | + label: '键名', | |
265 | + colProps: { span: 6 }, | |
266 | + component: 'Input', | |
267 | + defaultValue: 'sql', | |
268 | + componentProps: { | |
269 | + disabled: true, | |
270 | + }, | |
271 | + ifShow: ({ values }) => values['requestContentType'] === '1', | |
280 | 272 | }, |
281 | - ifShow: ({ values }) => values['requestContentType'] === '1', | |
282 | - }, | |
283 | - { | |
284 | - field: 'slot', | |
285 | - label: '参数设置', | |
286 | - component: 'Input', | |
287 | - slot: 'selectMethods', | |
288 | - colProps: { span: 24 }, | |
289 | - ifShow: ({ values }) => values['requestContentType'] !== '1', | |
290 | - }, | |
291 | -]; | |
273 | + { | |
274 | + field: 'requestSQLContent', | |
275 | + label: '键值', | |
276 | + colProps: { span: 24 }, | |
277 | + component: 'InputTextArea', | |
278 | + defaultValue: 'select * from where', | |
279 | + componentProps: { | |
280 | + maxLength: 255, | |
281 | + placeholder: '请输入键值', | |
282 | + rows: 6, | |
283 | + }, | |
284 | + ifShow: ({ values }) => values['requestContentType'] === '1', | |
285 | + }, | |
286 | + { | |
287 | + field: 'slot', | |
288 | + label: '参数设置', | |
289 | + component: 'Input', | |
290 | + slot: 'selectMethods', | |
291 | + colProps: { span: 24 }, | |
292 | + ifShow: ({ values }) => values['requestContentType'] !== '1', | |
293 | + }, | |
294 | + ]; | |
295 | +}; | |
292 | 296 | |
293 | 297 | //表格表头配置 |
294 | 298 | export const editCellTableTHeadConfig = ['序号', '内置参数', '参数名', '是否必须', '操作']; | ... | ... |
... | ... | @@ -71,9 +71,6 @@ |
71 | 71 | import { useUtils } from './hooks/useUtils'; |
72 | 72 | import { Tag } from 'ant-design-vue'; |
73 | 73 | import { RequestMethodTypeEnum, RequestOriginTypeEnum } from './config/enum'; |
74 | - import { isAdmin } from '/@/enums/roleEnum'; | |
75 | - import { USER_INFO_KEY } from '/@/enums/cacheEnum'; | |
76 | - import { getAuthCache } from '/@/utils/auth'; | |
77 | 74 | |
78 | 75 | const { |
79 | 76 | resetReqHttpType, |
... | ... | @@ -85,10 +82,6 @@ |
85 | 82 | |
86 | 83 | const emits = defineEmits(['success', 'register']); |
87 | 84 | |
88 | - const userInfo: any = getAuthCache(USER_INFO_KEY); | |
89 | - | |
90 | - const role: string = userInfo?.roles[0]; | |
91 | - | |
92 | 85 | const { createMessage } = useMessage(); |
93 | 86 | |
94 | 87 | const isUpdate = ref(false); |
... | ... | @@ -130,7 +123,7 @@ |
130 | 123 | |
131 | 124 | const [registerForm, { resetFields, validate, setFieldsValue, updateSchema }] = useForm({ |
132 | 125 | labelWidth: 120, |
133 | - schemas, | |
126 | + schemas: schemas(), | |
134 | 127 | showActionButtonGroup: false, |
135 | 128 | }); |
136 | 129 | |
... | ... | @@ -180,10 +173,6 @@ |
180 | 173 | const requestOriginUrl = getOriginUrlType(values); |
181 | 174 | const params = (Objects as Recordable)?.Params?.filter((item) => item.key); |
182 | 175 | (Objects as Recordable).Params = params; |
183 | - //超级管理员或平台管理员接口类型为系统默认 | |
184 | - if (isAdmin(role)) { | |
185 | - values.interfaceType = 'SYSTEM'; //系统默认 | |
186 | - } | |
187 | 176 | const data = { |
188 | 177 | ...values, |
189 | 178 | id: !putId.value ? null : putId.value, | ... | ... |