feat:组织机构-添加API授权相关
parent
fbfe6d1cd4
commit
a3d315ec86
@ -0,0 +1,113 @@
|
||||
<template>
|
||||
<BasicModal
|
||||
v-bind="$attrs"
|
||||
:use-wrapper="true"
|
||||
:title="getTitle"
|
||||
width="50%"
|
||||
@register="registerModal"
|
||||
@ok="handleSave"
|
||||
>
|
||||
<BasicForm @register="registerForm">
|
||||
<template #status="item">
|
||||
<a-switch @change="changeStatus" v-model:checked="item.values.status" />
|
||||
<span class="s-txt" :class="{ 's-active': item.values.status }">
|
||||
{{ item.values.status ? '启用' : '禁用' }}
|
||||
</span>
|
||||
</template>
|
||||
</BasicForm>
|
||||
|
||||
<!--右下角按钮-->
|
||||
<template #footer>
|
||||
<a-button type="default" :loading="loading" @click="closeModal">取消</a-button>
|
||||
<a-button type="primary" :loading="loading" @click="handleSave(true)">保存</a-button>
|
||||
</template>
|
||||
</BasicModal>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { ref, computed, unref } from 'vue'
|
||||
import { BasicModal, useModalInner } from '/@/components/Modal'
|
||||
import { BasicForm, useForm } from '/@/components/Form/index'
|
||||
import { APIformSchema } from './columns'
|
||||
|
||||
import { editOrgAuth, getOrgAuthInfo } from '/@/api/system/org'
|
||||
import { useMessage } from '/@/hooks/web/useMessage'
|
||||
// 声明Emits
|
||||
const emit = defineEmits(['success', 'register'])
|
||||
const isUpdate = ref(true)
|
||||
const loading = ref(false)
|
||||
const rowId = ref('')
|
||||
const linkId = ref('')
|
||||
const { createMessage } = useMessage()
|
||||
const [registerForm, { resetFields, setFieldsValue, validate }] = useForm({
|
||||
labelWidth: 100,
|
||||
schemas: APIformSchema,
|
||||
showActionButtonGroup: false,
|
||||
})
|
||||
|
||||
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
|
||||
resetFields()
|
||||
setModalProps({ confirmLoading: false, loading: true })
|
||||
isUpdate.value = !!data?.isUpdate
|
||||
linkId.value = data.linkId ? data.linkId : ''
|
||||
if (unref(isUpdate)) {
|
||||
rowId.value = data.record.id ? data.record.id : data.record.value
|
||||
const res: API.DataResult = await getOrgAuthInfo({ id: unref(rowId) })
|
||||
if (res.data.status == 1) {
|
||||
res.data.status = false
|
||||
} else {
|
||||
res.data.status = true
|
||||
}
|
||||
if (res.succeeded) {
|
||||
setFieldsValue({
|
||||
...res.data,
|
||||
})
|
||||
}
|
||||
} else {
|
||||
setFieldsValue({ permissionIdentity: unref(2) })
|
||||
console.log(data.orgFullName)
|
||||
if (data.orgFullName) setFieldsValue({ accountName: data.orgFullName })
|
||||
}
|
||||
setModalProps({ loading: false })
|
||||
})
|
||||
const getTitle = computed(() => (!unref(isUpdate) ? '新增API授权' : '编辑API授权'))
|
||||
const changeStatus = (v) => {
|
||||
setFieldsValue({ status: v })
|
||||
}
|
||||
async function handleSave(exit) {
|
||||
try {
|
||||
const values = await validate()
|
||||
setModalProps({ confirmLoading: true, loading: true })
|
||||
values.linkId = values.linkId ? values.linkId : linkId.value
|
||||
if (values.status) {
|
||||
values.status = 0
|
||||
} else {
|
||||
values.status = 1
|
||||
}
|
||||
const res: API.DataResult = await editOrgAuth(values)
|
||||
|
||||
if (res.succeeded) {
|
||||
createMessage.success(res.message)
|
||||
emit('success')
|
||||
} else {
|
||||
createMessage.error(res.message)
|
||||
}
|
||||
|
||||
exit && closeModal()
|
||||
} finally {
|
||||
setModalProps({ confirmLoading: false, loading: false })
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.s-txt {
|
||||
font-size: 12px;
|
||||
margin-left: 10px;
|
||||
color: #7a8798;
|
||||
position: relative;
|
||||
top: 1px;
|
||||
}
|
||||
.s-active {
|
||||
color: #257afa;
|
||||
}
|
||||
</style>
|
Loading…
Reference in New Issue