数据权限

szh-new
sunzehua 3 months ago
parent 18e2959d18
commit 9f88ee673a

@ -1,145 +1,3 @@
<template>
<BasicModal
v-bind="$attrs"
:use-wrapper="true"
:title="getTitle"
width="50%"
@register="registerModal"
@ok="handleSave"
>
<BasicForm @register="registerForm"> </BasicForm>
<!--右下角按钮-->
<template #footer>
<a-button
pre-icon="ant-design:close-outlined"
type="warning"
:loading="loading"
ghost
style="margin-right: 0.8rem"
@click="closeModal"
>取消</a-button
>
<a-button
type="success"
:loading="loading"
pre-icon="ant-design:check-outlined"
style="margin-right: 0.8rem"
@click="handleSave(false)"
>仅保存</a-button
>
<a-button
pre-icon="ant-design:check-circle-outlined"
type="primary"
:loading="loading"
@click="handleSave(true)"
>保存并关闭</a-button
>
</template>
</BasicModal>
</template>
<script lang="ts" setup>
import { ref, computed, unref, h } from 'vue'
import { BasicModal, useModalInner } from '/@/components/Modal'
import { BasicForm, useForm } from '/@/components/Form/index'
import { formSchema } from './columns'
import { editDataRule, getDataRuleInfo } from '/@/api/system/datarule'
import { useUserStore } from '/@/store/modules/user'
import { useMessage } from '/@/hooks/web/useMessage'
import { Field } from '/@/components/Render/interface'
// Emits
const emit = defineEmits(['success', 'register'])
const isUpdate = ref(true)
const loading = ref(false)
const rowId = ref('')
const conditions = ref('')
const fields = ref<Field[]>([])
const { createMessage } = useMessage()
const [registerForm, { resetFields, setFieldsValue, validate, updateSchema, getFieldsValue }] =
useForm({
labelWidth: 110,
schemas: formSchema,
showActionButtonGroup: false,
})
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
resetFields()
// GetTable()
setModalProps({ confirmLoading: false, loading: true })
isUpdate.value = !!data?.isUpdate
if (unref(isUpdate)) {
// setModalProps({ confirmLoading: true });
rowId.value = data.record.id
const res: API.DataResult = await getDataRuleInfo({ id: unref(rowId) })
if (res.succeeded) {
setFieldsValue({
...res.data,
field1: JSON.parse(res.data.dataRules),
})
// console.log('Form', getFieldsValue());
// setFieldsValue({ trainId: unref(res.data.trainId) });
}
// setModalProps({ confirmLoading: false });
} else {
}
setModalProps({ loading: false })
})
const getTitle = computed(() => (!unref(isUpdate) ? '新增数据权限' : '编辑数据权限'))
async function handleSave(exit) {
try {
const values = await validate()
setModalProps({ confirmLoading: true, loading: true })
// TODO custom api
values.dataRules = JSON.stringify(values.field1)
console.log(values)
loading.value = true
const res: API.DataResult = await editDataRule({
columnView: values.columnView,
dataRules: values.dataRules,
description: values.description,
id: values.id,
note: values.note,
orderNo: values.orderNo,
permissionEntity: values.permissionEntity,
permissionId: values.permissionId,
status: values.status,
})
console.log(res)
if (res.succeeded) {
createMessage.success(res.message)
emit('success')
//
if (!exit) {
if (unref(isUpdate)) {
await refresh()
} else {
rowId.value = res.data
isUpdate.value = true
await refresh()
}
}
loading.value = false
} else {
createMessage.error(res.message)
loading.value = false
setModalProps({ confirmLoading: false, loading: false })
}
exit && closeModal()
} finally {
loading.value = false
setModalProps({ confirmLoading: false, loading: false })
}
}
async function refresh() {
const res: API.DataResult = await getDataRuleInfo({ id: unref(rowId) })
if (res.succeeded) {
await setFieldsValue({
...res.data,
})
}
}
</script>
</template>
Loading…
Cancel
Save