|
@@ -1,157 +1,263 @@
|
|
|
-<script lang="ts" setup>
|
|
|
-import { ref, watch, shallowRef } from "vue"
|
|
|
-import { useVModel } from "@vueuse/core"
|
|
|
+<script setup lang="ts">
|
|
|
+import { reactive, ref, onMounted, watch, shallowRef } from "vue";
|
|
|
+import { useColumns } from "./columns";
|
|
|
+import { httpList, httpStatus, httpDetail, httpAdd } from "/@/api/interest/role";
|
|
|
+import { type FormInstance } from "element-plus";
|
|
|
+import { ElMessage } from "element-plus";
|
|
|
+import { TableProBar } from "/@/components/ReTable";
|
|
|
+import { type PaginationProps } from "@pureadmin/table";
|
|
|
+import { useRenderIcon } from "/@/components/ReIcon/src/hooks";
|
|
|
+import { useNav } from "/@/layout/hooks/nav";
|
|
|
+import { statusList } from "/@/utils/status";
|
|
|
+import { responseHandle } from "/@/utils/responseHandle";
|
|
|
+import { useUserStoreHook } from "/@/store/modules/user";
|
|
|
+import addEdit from "./addEdit.vue";
|
|
|
import { useCompany } from "/@/hooks/core/useCompany";
|
|
|
-import { BusinessQuery } from "/@/components/BasicForm";
|
|
|
-import { httpList, httpUpdate } from "/@/api/interest/role";
|
|
|
+import { useUserInfo } from "/@/hooks/core/useUser";
|
|
|
|
|
|
-import { httpDetail, httpAdd } from "/@/api/interest/role";
|
|
|
+import RoleCopy from "./role-copy.vue"
|
|
|
+const { logout } = useNav();
|
|
|
|
|
|
-import { ElMessage } from "element-plus"
|
|
|
+defineOptions({
|
|
|
+ name: "role"
|
|
|
+});
|
|
|
|
|
|
-const props = defineProps<{
|
|
|
- companyNo: string
|
|
|
- roleName: string
|
|
|
- visible: boolean
|
|
|
- roleId: string
|
|
|
-}>()
|
|
|
+const form = reactive({
|
|
|
+ level: "",
|
|
|
+ role_name: "",
|
|
|
+ status: "",
|
|
|
+ page: 1,
|
|
|
+ size: 15
|
|
|
+});
|
|
|
|
|
|
-const emit = defineEmits(['refresh'])
|
|
|
+const powers = ref([]);
|
|
|
+const dataList = ref([]);
|
|
|
+const loading = ref(true);
|
|
|
+const { columns } = useColumns();
|
|
|
+const showModel = ref(false);
|
|
|
+const itemId = ref("");
|
|
|
+const isDetails = ref("add");
|
|
|
+const formRef = ref<FormInstance>();
|
|
|
|
|
|
-
|
|
|
-const visible = useVModel(props, 'visible')
|
|
|
-const formRef = ref<any>(null)
|
|
|
const { currentCompany } = useCompany();
|
|
|
+const { isSuperUser, userInfo } = useUserInfo();
|
|
|
|
|
|
|
|
|
-const roles = ref<any[]>([])
|
|
|
-const loading = shallowRef(false)
|
|
|
+// console.log()
|
|
|
+const pagination = reactive<PaginationProps>({
|
|
|
+ total: 0,
|
|
|
+ pageSize: 15,
|
|
|
+ currentPage: 1,
|
|
|
+ background: true
|
|
|
+});
|
|
|
+//修改状态
|
|
|
+const handleStatus = async row => {
|
|
|
+ const { id, status } = row;
|
|
|
+ const { code, message } = await httpStatus({
|
|
|
+ roleid: id,
|
|
|
+ status: status + "" === "1" ? "0" : "1"
|
|
|
+ });
|
|
|
+ responseHandle({
|
|
|
+ code,
|
|
|
+ message,
|
|
|
+ logout,
|
|
|
+ handler: () => onSearch()
|
|
|
+ });
|
|
|
+};
|
|
|
|
|
|
-const initialData = {
|
|
|
- name: '',
|
|
|
- companyNo: '',
|
|
|
- sourceRoleId: '',
|
|
|
- sourceCompanyNo: ''
|
|
|
+async function handleCurrentChange(val: number) {
|
|
|
+ form.page = val;
|
|
|
+ await onSearch();
|
|
|
}
|
|
|
|
|
|
-const formData = ref({ ...initialData })
|
|
|
-
|
|
|
+async function handleSizeChange(val: number) {
|
|
|
+ form.size = val;
|
|
|
+ form.page = 1;
|
|
|
+ await onSearch();
|
|
|
+}
|
|
|
|
|
|
-watch(
|
|
|
- () => currentCompany.value,
|
|
|
- () => formData.value.companyNo = currentCompany.value.companyNo
|
|
|
-);
|
|
|
+function handleSelectionChange(val) {
|
|
|
+ console.log("handleSelectionChange", val);
|
|
|
+}
|
|
|
|
|
|
-async function requestRoles(companyNo: string) {
|
|
|
+async function onSearch() {
|
|
|
loading.value = true;
|
|
|
const { code, data, message } = await httpList({
|
|
|
- size: 1000,
|
|
|
+ ...form,
|
|
|
level: "2",
|
|
|
- companyNo
|
|
|
+ companyNo: currentCompany.value.companyNo
|
|
|
});
|
|
|
-
|
|
|
if (code === 0) {
|
|
|
const { list, count } = data;
|
|
|
- roles.value = list
|
|
|
+ dataList.value = list ?? [];
|
|
|
+ pagination.total = count ?? 0;
|
|
|
+ pagination.pageSize = form.size;
|
|
|
+ pagination.currentPage = form.page;
|
|
|
+ } else if (code > 100 && code < 140) {
|
|
|
+ logout();
|
|
|
+ } else {
|
|
|
+ ElMessage.error(message);
|
|
|
}
|
|
|
-
|
|
|
loading.value = false;
|
|
|
}
|
|
|
-
|
|
|
-watch(() => formData.value.sourceCompanyNo, (value) => {
|
|
|
- roles.value = []
|
|
|
- formData.value.sourceRoleId = ""
|
|
|
- if (!formData.value.sourceCompanyNo) { return }
|
|
|
- requestRoles(formData.value.sourceCompanyNo)
|
|
|
-}, {
|
|
|
- immediate: true
|
|
|
-})
|
|
|
-
|
|
|
-const rules = {
|
|
|
- // "name": [{ required: true, message: '请输入角色名称', trigger: 'change' }],
|
|
|
- "sourceCompanyNo": [{ required: true, message: '请选择来源业务公司', trigger: 'change' }],
|
|
|
- "sourceRoleId": [{ required: true, message: '请选择来源角色', trigger: 'change' }],
|
|
|
+async function resetSearch() {
|
|
|
+ form.page = 1;
|
|
|
+ await onSearch();
|
|
|
}
|
|
|
+//新建/编辑/详情弹窗
|
|
|
+function editItem(id, type) {
|
|
|
+ if (!currentCompany.value.companyNo) {
|
|
|
+ ElMessage.warning("请选择一个公司");
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
-function handleClose() {
|
|
|
- formData.value = { ...initialData }
|
|
|
- visible.value = false
|
|
|
+ itemId.value = id;
|
|
|
+ isDetails.value = type;
|
|
|
+ showModel.value = true;
|
|
|
}
|
|
|
+const submitRefresh = () => {
|
|
|
+ showModel.value = false;
|
|
|
+ onSearch();
|
|
|
+};
|
|
|
+const submitCancel = () => {
|
|
|
+ showModel.value = false;
|
|
|
+};
|
|
|
|
|
|
-async function requestRole() {
|
|
|
- try {
|
|
|
- const { sourceCompanyNo, sourceRoleId } = formData.value
|
|
|
- const { data, code } = await httpDetail({ companyNo: sourceCompanyNo, roleid: sourceRoleId });
|
|
|
- if (code === 0) {
|
|
|
- return data
|
|
|
- } else {
|
|
|
- throw new Error('读取角色失败..')
|
|
|
- }
|
|
|
- } catch (err) {
|
|
|
- throw new Error('读取角色失败..')
|
|
|
- }
|
|
|
-}
|
|
|
+const resetForm = (formEl: FormInstance | undefined) => {
|
|
|
+ if (!formEl) return;
|
|
|
+ formEl.resetFields();
|
|
|
+ form.page = 1;
|
|
|
+ onSearch();
|
|
|
+};
|
|
|
|
|
|
-async function createRole(params = {}) {
|
|
|
- try {
|
|
|
- const { data, code } = await httpUpdate(params);
|
|
|
- if (code !== 0) { throw new Error('复制角色失败..') }
|
|
|
- } catch (err) {
|
|
|
- throw new Error('复制角色失败..')
|
|
|
- }
|
|
|
-}
|
|
|
+async function setRoles() {
|
|
|
+ const { data } = await httpList({ level: "2", size: 1000, companyNo: 'GS2203161855277894' });
|
|
|
+ const { list } = data;
|
|
|
+
|
|
|
+ for (const item of list) {
|
|
|
+ const { data: detail } = await httpDetail({ roleid: item.id });
|
|
|
|
|
|
+ const {
|
|
|
+ action,
|
|
|
+ private_data,
|
|
|
+ role_name,
|
|
|
+ } = detail;
|
|
|
|
|
|
-async function onSubmit() {
|
|
|
- try {
|
|
|
- loading.value = true
|
|
|
- await formRef.value.validate();
|
|
|
- const { sourceCompanyNo, sourceRoleId, companyNo, name } = formData.value
|
|
|
- ElMessage.info('正在读取来源角色信息(1/3)...')
|
|
|
- const detail = await requestRole()
|
|
|
- ElMessage.info('读取角色信息成功,正在复制角色(2/3)...')
|
|
|
- const { action, private_data, role_name } = detail;
|
|
|
const params = {
|
|
|
- level: 2,
|
|
|
- roleid: props.roleId,
|
|
|
- role_name: props.roleName,
|
|
|
- companyNo: props.companyNo,
|
|
|
action: Array.isArray(action) ? action : action.split(','),
|
|
|
- private_data:( Array.isArray(private_data) ? private_data : private_data.split(',')).filter(item => !!item)
|
|
|
+ level: 2,
|
|
|
+ companyNo: currentCompany.value.companyNo,
|
|
|
+ role_name,
|
|
|
+ private_data: Array.isArray(private_data) ? private_data : private_data.split(',')
|
|
|
};
|
|
|
- await createRole(params)
|
|
|
- loading.value = false
|
|
|
- ElMessage.success('角色复制成功(3/3)...')
|
|
|
- emit('refresh')
|
|
|
- visible.value = false
|
|
|
- } catch (err) {
|
|
|
- ElMessage.warning(err)
|
|
|
- loading.value = false
|
|
|
+
|
|
|
+ await httpAdd(params);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+const roleId = shallowRef("")
|
|
|
+const roleName = shallowRef("")
|
|
|
+const companyNo = shallowRef("")
|
|
|
+const visible = shallowRef(false)
|
|
|
+function handleCopy(row){
|
|
|
+ const { id, role_name } = row
|
|
|
+ roleId.value = id
|
|
|
+ roleName.value = role_name
|
|
|
+ companyNo.value = row.companyNo
|
|
|
+ visible.value = true
|
|
|
+}
|
|
|
+
|
|
|
+onMounted(() => {
|
|
|
+ powers.value = useUserStoreHook().getMenuActions("role");
|
|
|
+ if (powers.value.some(i => i == "001")) {
|
|
|
+ onSearch();
|
|
|
+ }
|
|
|
+});
|
|
|
+
|
|
|
+watch(
|
|
|
+ () => currentCompany.value,
|
|
|
+ () => onSearch()
|
|
|
+);
|
|
|
</script>
|
|
|
|
|
|
<template>
|
|
|
- <ElDialog title="复制角色" center v-model="visible" @close="handleClose">
|
|
|
- <ElForm :model="formData" :rules="rules" ref="formRef" v-loading="loading" label-width="80px">
|
|
|
- <ElFormItem prop="name" label="角色名称">
|
|
|
- <ElInput :modelValue="roleName" placeholder="角色名称" disabled />
|
|
|
- </ElFormItem>
|
|
|
-
|
|
|
- <ElFormItem prop="sourceCompanyNo" label="来源公司">
|
|
|
- <BusinessQuery v-model="formData.sourceCompanyNo" placeholder="来源公司" />
|
|
|
- </ElFormItem>
|
|
|
-
|
|
|
- <ElFormItem prop="sourceRoleId" label="来源角色">
|
|
|
- <ElSelect v-model="formData.sourceRoleId" style="width:100%" placeholder="来源角色"
|
|
|
- :disabled="!formData.sourceCompanyNo">
|
|
|
- <ElOption v-for="role in roles" :key="role.id" :value="role.id" :label="role.role_name" :disabled="role.id === roleId" />
|
|
|
- </ElSelect>
|
|
|
- </ElFormItem>
|
|
|
-
|
|
|
- <div class="w-full flex justify-end">
|
|
|
- <ElButton type="primary" @click="onSubmit">保存</ElButton>
|
|
|
- </div>
|
|
|
- </ElForm>
|
|
|
- </ElDialog>
|
|
|
+ <div class="main role">
|
|
|
+ <!-- <el-button @click="setRoles">设置角色</el-button> -->
|
|
|
+ <div v-show="powers.some(i => i == '001')">
|
|
|
+ <el-form ref="formRef" :inline="true" :model="form" size="small" :label-width="0"
|
|
|
+ class="bg-white w-99/100 pl-8 pt-4">
|
|
|
+ <el-form-item prop="status">
|
|
|
+ <el-select v-model="form.status" style="width: 100%" placeholder="角色状态" clearable>
|
|
|
+ <el-option v-for="(si, sii) in statusList" :key="'status' + si.value + sii" :label="si.label"
|
|
|
+ :value="si.value" />
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item prop="role_name">
|
|
|
+ <el-input v-model="form.role_name" placeholder="角色名称" clearable />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item>
|
|
|
+ <el-button type="primary" :icon="useRenderIcon('search')" :loading="loading" @click="resetSearch">
|
|
|
+ 搜索
|
|
|
+ </el-button>
|
|
|
+ <el-button :icon="useRenderIcon('refresh')" @click="resetForm(formRef)">
|
|
|
+ 重置
|
|
|
+ </el-button>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+
|
|
|
+ <TableProBar title="公司角色管理" :loading="loading" :dataList="dataList" @refresh="onSearch">
|
|
|
+ <template #buttons>
|
|
|
+ <el-button type="primary" size="small" v-if="powers.some(i => i == '002')" :icon="useRenderIcon('add')"
|
|
|
+ @click="editItem('', 'add')">
|
|
|
+ 新增角色
|
|
|
+ </el-button>
|
|
|
+ </template>
|
|
|
+ <template v-slot="{ size, checkList }">
|
|
|
+ <PureTable border align="left" showOverflowTooltip table-layout="auto" size="small" :data="dataList"
|
|
|
+ :columns="columns" :checkList="checkList" :pagination="pagination"
|
|
|
+ :paginationSmall="size === 'small' ? true : false"
|
|
|
+ :header-cell-style="{ background: '#fafafa', color: '#606266' }" @selection-change="handleSelectionChange"
|
|
|
+ @size-change="handleSizeChange" @current-change="handleCurrentChange">
|
|
|
+ <template #operation="{ row }">
|
|
|
+ <el-button class="reset-margin" link type="primary" v-if="powers.some(i => i == '007')" :size="size"
|
|
|
+ @click="editItem(row.id, 'view')" :icon="useRenderIcon('eye-view')" />
|
|
|
+ <el-button class="reset-margin" link type="primary" :size="size" v-if="powers.some(i => i == '005')"
|
|
|
+ @click="editItem(row.id, 'edit')" :icon="useRenderIcon('edits')" />
|
|
|
+ <el-popconfirm :title="row.status === '1' ? '改为禁用?' : '改为启用?'" v-if="(powers.some(i => i == '004') && row.status + '' === '1') ||
|
|
|
+ (powers.some(i => i == '003') && row.status + '' === '0')
|
|
|
+ " @confirm="handleStatus(row)">
|
|
|
+ <template #reference>
|
|
|
+ <el-button class="reset-margin" link type="primary" :size="size" :icon="useRenderIcon(
|
|
|
+ row.status === '1'
|
|
|
+ ? 'close-circle-line'
|
|
|
+ : 'checkbox-circle-line'
|
|
|
+ )
|
|
|
+ " /></template></el-popconfirm>
|
|
|
+
|
|
|
+
|
|
|
+ <el-tooltip content="复制角色" v-if="isSuperUser && String(userInfo.id) !== '156'">
|
|
|
+ <el-button
|
|
|
+ class="reset-margin" link type="primary"
|
|
|
+ @click="handleCopy(row)"
|
|
|
+ :size="size"
|
|
|
+ :icon="useRenderIcon('dict')" />
|
|
|
+ </el-tooltip>
|
|
|
+ </template>
|
|
|
+ </PureTable>
|
|
|
+ </template>
|
|
|
+ </TableProBar>
|
|
|
+ <addEdit :itemId="itemId" :isDetails="isDetails" :show-model="showModel" @refresh="submitRefresh"
|
|
|
+ @cancel="submitCancel" />
|
|
|
+
|
|
|
+ <RoleCopy v-model:visible="visible" :roleId="roleId" :roleName="roleName" :companyNo="companyNo" @refresh="onSearch" />
|
|
|
+ </div>
|
|
|
+ <NoAuth v-show="!powers.some(i => i == '001')" />
|
|
|
+ </div>
|
|
|
</template>
|
|
|
+
|
|
|
+<style scoped lang="scss">
|
|
|
+:deep(.el-dropdown-menu__item i) {
|
|
|
+ margin: 0;
|
|
|
+}
|
|
|
+</style>
|