This commit is contained in:
weipengfei 2023-08-26 10:51:40 +08:00
parent 11006bf7ff
commit 06ea40c91c
3 changed files with 33 additions and 15 deletions

View File

@ -4,6 +4,7 @@ import { reactive, toRaw } from "vue";
interface Options {
page?: number;
size?: number;
limit?: number;
fetchFun: (_arg: any) => Promise<any>;
params?: Record<any, any>;
firstLoading?: boolean;
@ -39,6 +40,7 @@ export function usePaging(options: Options) {
.then((res: any) => {
pager.count = res?.count;
res.lists ? (pager.lists = res.lists) : (pager.lists = res.data);
if(pager.lists==[]||pager.lists==null||pager.lists==undefined)res.list ? pager.lists = res.list: null;
// pager.lists = res?.lists
pager.extend = res?.extend;
return Promise.resolve(res);

View File

@ -15,7 +15,7 @@
v-model="queryParams.company_type"
placeholder="公司类型"
clearable
@change="getLists"
@change="changeType"
:style="{ width: '100%' }"
>
<el-option
@ -42,9 +42,15 @@
<div class="mt-4">
<el-table :data="pager.lists" @cell-click="handleCurrentChange">
<el-table-column label="公司名称" property="company_name" />
<el-table-column label="公司类型" property="company_type" />
<el-table-column label="区县" property="area" />
<el-table-column label="乡镇" property="street" />
<el-table-column label="公司类型" property="company_type">
<template #default="{ row }">
<span
>{{typeList.find((item: any)=>item.id==row.company_type).name}}</span
>
</template>
</el-table-column>
<el-table-column label="区县" property="area_name" />
<el-table-column label="乡镇" property="street_name" />
<el-table-column label="主联系人" property="master_name" />
<el-table-column label="联系方式" property="master_phone" />
</el-table>
@ -59,7 +65,11 @@
<script lang="ts" setup name="companyLists">
import { usePaging } from "@/hooks/usePaging";
import { useDictData } from "@/hooks/useDictOptions";
import { apiCompanyLists, apiCompanyDelete } from "@/api/company";
import {
apiCompanyLists,
companyListTwo,
apiCompanyDelete,
} from "@/api/company";
import { defineEmits } from "vue";
//
@ -115,9 +125,14 @@ const handleCurrentChange = (value: any) => {
emits("customEvent", value);
};
//
const changeType = (e: any) => {
getLists();
};
//
const { pager, getLists, resetParams, resetPage } = usePaging({
fetchFun: apiCompanyLists,
fetchFun: companyListTwo,
params: queryParams,
});

View File

@ -17,7 +17,7 @@
v-loading="loading"
>
<el-scrollbar class="h-[400px] sm:h-[600px]">
<el-form-item label="权限" prop="menu_id">
<el-form-item label="权限" prop="menu_arr">
<div>
<el-checkbox label="展开/折叠" @change="handleExpand" />
<el-checkbox label="全选/不全选" @change="handleSelectAll" />
@ -48,7 +48,9 @@ import type { CheckboxValueType, ElTree, FormInstance } from "element-plus";
import { roleEdit } from "@/api/perms/role";
import Popup from "@/components/popup/index.vue";
import { treeToArray } from "@/utils/util";
import { menuAll } from "@/api/perms/menu";
// import { menuAll } from "@/api/perms/menu";
import { apiUserMenuLists } from "@/api/user_menu";
import { apiUserRoleEdit } from "@/api/user_role";
const emit = defineEmits(["success", "close"]);
const treeRef = shallowRef<InstanceType<typeof ElTree>>();
const formRef = shallowRef<FormInstance>();
@ -63,7 +65,7 @@ const formData = reactive({
name: "",
desc: "",
sort: 0,
menu_id: [] as any[],
menu_arr: [] as any[],
});
const rules = {
@ -78,9 +80,8 @@ const rules = {
const getOptions = () => {
loading.value = true;
menuAll().then((res: any) => {
menuTree.value = res;
menuArray.value = treeToArray(res);
apiUserMenuLists().then((res: any) => {
menuTree.value = res.lists;
nextTick(() => {
setDeptAllCheckedKeys();
});
@ -97,7 +98,7 @@ const getDeptAllCheckedKeys = () => {
};
const setDeptAllCheckedKeys = () => {
formData.menu_id.forEach((v) => {
formData.menu_arr.forEach((v) => {
nextTick(() => {
treeRef.value?.setChecked(v, true, false);
});
@ -122,8 +123,8 @@ const handleSelectAll = (check: CheckboxValueType) => {
const handleSubmit = async () => {
await formRef.value?.validate();
formData.menu_id = getDeptAllCheckedKeys()!;
await roleEdit(formData);
formData.menu_arr = getDeptAllCheckedKeys()!;
await apiUserRoleEdit(formData);
popupRef.value?.close();
emit("success");
};