169 lines
4.9 KiB
Vue
Raw Normal View History

2022-11-13 14:40:51 +08:00
<template>
<ContentWrap>
<!-- 列表 -->
<vxe-grid ref="xGrid" v-bind="gridOptions" class="xtable-scrollbar">
<template #toolbar_buttons>
2022-11-16 10:00:59 +08:00
<!-- 操作新增 -->
2022-11-13 14:40:51 +08:00
<XButton
type="primary"
preIcon="ep:zoom-in"
:title="t('action.add')"
v-hasPermi="['system:oauth2-client:create']"
@click="handleCreate()"
/>
</template>
2022-11-15 13:59:22 +08:00
<template #authorizedGrantTypes_default="{ row }">
2022-11-13 14:40:51 +08:00
<el-tag
:disable-transitions="true"
:key="index"
v-for="(authorizedGrantType, index) in row.authorizedGrantTypes"
:index="index"
>
{{ authorizedGrantType }}
</el-tag>
</template>
<template #actionbtns_default="{ row }">
<!-- 操作修改 -->
<XTextButton
preIcon="ep:edit"
:title="t('action.edit')"
v-hasPermi="['system:oauth2-client:update']"
@click="handleUpdate(row.id)"
/>
<!-- 操作详情 -->
<XTextButton
preIcon="ep:view"
:title="t('action.detail')"
2022-11-16 10:07:24 +08:00
v-hasPermi="['system:oauth2-client:query']"
2022-11-13 14:40:51 +08:00
@click="handleDetail(row.id)"
/>
<!-- 操作删除 -->
<XTextButton
preIcon="ep:delete"
:title="t('action.del')"
v-hasPermi="['system:oauth2-client:delete']"
@click="handleDelete(row.id)"
/>
</template>
</vxe-grid>
</ContentWrap>
<!-- 弹窗 -->
2022-11-15 12:25:19 +08:00
<XModal id="postModel" v-model="dialogVisible" :title="dialogTitle">
2022-11-14 09:15:11 +08:00
<!-- 表单添加/修改 -->
<Form
ref="formRef"
v-if="['create', 'update'].includes(actionType)"
:schema="allSchemas.formSchema"
:rules="rules"
/>
<!-- 表单详情 -->
<Descriptions
v-if="actionType === 'detail'"
:schema="allSchemas.detailSchema"
:data="detailRef"
/>
2022-11-13 14:40:51 +08:00
<template #footer>
<!-- 按钮保存 -->
<XButton
v-if="['create', 'update'].includes(actionType)"
type="primary"
:title="t('action.save')"
:loading="actionLoading"
2022-11-15 17:42:04 +08:00
@click="submitForm()"
2022-11-13 14:40:51 +08:00
/>
<!-- 按钮关闭 -->
<XButton :loading="actionLoading" :title="t('dialog.close')" @click="dialogVisible = false" />
</template>
2022-11-15 12:25:19 +08:00
</XModal>
2022-11-13 14:40:51 +08:00
</template>
2022-07-18 19:06:37 +08:00
<script setup lang="ts">
2022-11-13 14:40:51 +08:00
// 全局相关的 import
2022-07-18 19:06:37 +08:00
import { ref, unref } from 'vue'
2022-11-13 14:40:51 +08:00
import { ElTag } from 'element-plus'
2022-07-18 19:06:37 +08:00
import { useI18n } from '@/hooks/web/useI18n'
2022-11-13 14:40:51 +08:00
import { useMessage } from '@/hooks/web/useMessage'
import { useVxeGrid } from '@/hooks/web/useVxeGrid'
import { VxeGridInstance } from 'vxe-table'
2022-07-18 19:06:37 +08:00
import { FormExpose } from '@/components/Form'
2022-11-13 14:40:51 +08:00
// 业务相关的 import
2022-07-18 19:06:37 +08:00
import * as ClientApi from '@/api/system/oauth2/client'
2022-11-13 14:40:51 +08:00
import { rules, allSchemas } from './client.data'
2022-07-18 19:06:37 +08:00
const { t } = useI18n() // 国际化
2022-11-13 14:40:51 +08:00
const message = useMessage() // 消息弹窗
2022-07-18 19:06:37 +08:00
2022-11-13 14:40:51 +08:00
// 列表相关的变量
const xGrid = ref<VxeGridInstance>() // 列表 Grid Ref
2022-11-16 10:28:28 +08:00
const { gridOptions, reloadList, deleteData } = useVxeGrid<ClientApi.OAuth2ClientVO>({
2022-11-13 14:40:51 +08:00
allSchemas: allSchemas,
2022-11-15 14:39:39 +08:00
getListApi: ClientApi.getOAuth2ClientPageApi,
2022-11-16 10:28:28 +08:00
deleteApi: ClientApi.deleteOAuth2ClientApi
2022-07-18 19:06:37 +08:00
})
2022-11-13 14:40:51 +08:00
// 弹窗相关的变量
2022-07-18 19:06:37 +08:00
const dialogVisible = ref(false) // 是否显示弹出层
const dialogTitle = ref('edit') // 弹出层标题
2022-11-13 14:40:51 +08:00
const actionType = ref('') // 操作按钮的类型
const actionLoading = ref(false) // 按钮 Loading
2022-07-18 19:06:37 +08:00
const formRef = ref<FormExpose>() // 表单 Ref
2022-11-13 14:40:51 +08:00
const detailRef = ref() // 详情 Ref
2022-07-18 19:06:37 +08:00
// 设置标题
const setDialogTile = (type: string) => {
dialogTitle.value = t('action.' + type)
actionType.value = type
dialogVisible.value = true
}
// 新增操作
const handleCreate = () => {
setDialogTile('create')
}
// 修改操作
2022-11-13 14:40:51 +08:00
const handleUpdate = async (rowId: number) => {
2022-07-18 19:06:37 +08:00
// 设置数据
2022-11-13 14:40:51 +08:00
const res = await ClientApi.getOAuth2ClientApi(rowId)
2022-07-18 19:06:37 +08:00
unref(formRef)?.setValues(res)
2022-11-16 10:28:28 +08:00
setDialogTile('update')
2022-07-18 19:06:37 +08:00
}
2022-11-13 14:40:51 +08:00
// 详情操作
const handleDetail = async (rowId: number) => {
const res = await ClientApi.getOAuth2ClientApi(rowId)
detailRef.value = res
2022-11-16 10:28:28 +08:00
setDialogTile('detail')
2022-11-13 14:40:51 +08:00
}
// 删除操作
const handleDelete = async (rowId: number) => {
2022-11-16 10:28:28 +08:00
await deleteData(xGrid, rowId)
2022-11-13 14:40:51 +08:00
}
// 提交新增/修改的表单
2022-07-18 19:06:37 +08:00
const submitForm = async () => {
2022-10-17 11:24:22 +08:00
const elForm = unref(formRef)?.getElFormRef()
if (!elForm) return
elForm.validate(async (valid) => {
if (valid) {
actionLoading.value = true
// 提交请求
try {
2022-11-13 14:40:51 +08:00
const data = unref(formRef)?.formModel as ClientApi.OAuth2ClientVO
2022-10-17 11:24:22 +08:00
if (actionType.value === 'create') {
await ClientApi.createOAuth2ClientApi(data)
2022-11-13 14:40:51 +08:00
message.success(t('common.createSuccess'))
2022-10-17 11:24:22 +08:00
} else {
await ClientApi.updateOAuth2ClientApi(data)
2022-11-13 14:40:51 +08:00
message.success(t('common.updateSuccess'))
2022-10-17 11:24:22 +08:00
}
dialogVisible.value = false
} finally {
actionLoading.value = false
2022-11-13 14:40:51 +08:00
// 刷新列表
2022-11-16 10:28:28 +08:00
await reloadList(xGrid)
2022-10-17 11:24:22 +08:00
}
2022-07-18 19:06:37 +08:00
}
2022-10-17 11:24:22 +08:00
})
2022-07-18 19:06:37 +08:00
}
</script>