feat: uploadImg 组件

This commit is contained in:
xingyu4j
2022-11-29 18:00:44 +08:00
parent ba547e9e2d
commit 93dd8b7b56
5 changed files with 183 additions and 4 deletions

View File

@ -12,7 +12,6 @@ export const rules = reactive({
clientId: [required],
secret: [required],
name: [required],
logo: [required],
status: [required],
accessTokenValiditySeconds: [required],
refreshTokenValiditySeconds: [required],

View File

@ -61,7 +61,11 @@
v-if="['create', 'update'].includes(actionType)"
:schema="allSchemas.formSchema"
:rules="rules"
/>
>
<template #logo>
<UploadImg :imgs="uploadLogo" :limit="1" />
</template>
</Form>
<!-- 表单详情 -->
<Descriptions
v-if="actionType === 'detail'"
@ -138,6 +142,7 @@ import { useMessage } from '@/hooks/web/useMessage'
import { useVxeGrid } from '@/hooks/web/useVxeGrid'
import { VxeGridInstance } from 'vxe-table'
import { FormExpose } from '@/components/Form'
import { UploadImg } from '@/components/UploadFile'
// 业务相关的 import
import * as ClientApi from '@/api/system/oauth2/client'
import { rules, allSchemas } from './client.data'
@ -159,7 +164,7 @@ const actionType = ref('') // 操作按钮的类型
const actionLoading = ref(false) // 按钮 Loading
const formRef = ref<FormExpose>() // 表单 Ref
const detailRef = ref() // 详情 Ref
const uploadLogo = ref('')
// 设置标题
const setDialogTile = (type: string) => {
dialogTitle.value = t('action.' + type)
@ -169,6 +174,7 @@ const setDialogTile = (type: string) => {
// 新增操作
const handleCreate = () => {
uploadLogo.value = ''
setDialogTile('create')
}
@ -177,6 +183,7 @@ const handleUpdate = async (rowId: number) => {
setDialogTile('update')
// 设置数据
const res = await ClientApi.getOAuth2ClientApi(rowId)
uploadLogo.value = res.logo
unref(formRef)?.setValues(res)
}
@ -202,6 +209,7 @@ const submitForm = async () => {
// 提交请求
try {
const data = unref(formRef)?.formModel as ClientApi.OAuth2ClientVO
data.logo = uploadLogo.value
if (actionType.value === 'create') {
await ClientApi.createOAuth2ClientApi(data)
message.success(t('common.createSuccess'))