mirror of
https://github.com/thousmile/molly-multi-tenant.git
synced 2025-12-30 04:32:26 +00:00
1.修复ts el-cascader 类型兼容问题
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
<template>
|
||||
<el-cascader v-model="result" :options="props.options" :props="cascaderProps" filterable clearable />
|
||||
<el-cascader v-model="result" :options="cascaderOptions" :props="{ checkStrictly: true }" filterable clearable />
|
||||
</template>
|
||||
|
||||
<script setup lang="ts" name="CascaderDept">
|
||||
import { computed } from "vue"
|
||||
import { IPmsDept } from "@/types/pms"
|
||||
import type { CascaderValue } from "element-plus"
|
||||
import { flatTreeToCascaderOption } from "@/utils"
|
||||
const props = defineProps({
|
||||
modelValue: {
|
||||
type: Number,
|
||||
@@ -16,17 +18,18 @@ const props = defineProps({
|
||||
}
|
||||
})
|
||||
|
||||
const cascaderProps = { checkStrictly: true, value: "deptId", label: "deptName" }
|
||||
const cascaderOptions = flatTreeToCascaderOption(props.options, { value: "deptId", label: "deptName" })
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: "update:modelValue", value: Number): void
|
||||
}>()
|
||||
|
||||
const result = computed({
|
||||
get(): Number {
|
||||
get(): CascaderValue {
|
||||
return props.modelValue
|
||||
},
|
||||
set(val: Number[]) {
|
||||
set(data: CascaderValue) {
|
||||
const val = data as number[]
|
||||
if (val && val.length > 0) {
|
||||
const v1 = val[val.length - 1]
|
||||
emit("update:modelValue", v1)
|
||||
|
||||
@@ -54,14 +54,14 @@ const props = defineProps({
|
||||
})
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: "update:value", value: String): void
|
||||
(e: "update:value", value: string): void
|
||||
}>()
|
||||
|
||||
const result = computed({
|
||||
get(): String {
|
||||
get(): string {
|
||||
return props.value
|
||||
},
|
||||
set(v: String) {
|
||||
set(v: string) {
|
||||
emit("update:value", v)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -101,3 +101,27 @@ export interface IPushMessage {
|
||||
/** 状态 0.失败 1.成功 */
|
||||
status: number
|
||||
}
|
||||
|
||||
/** key value */
|
||||
export interface IStringEntry {
|
||||
/**
|
||||
* 租户ID
|
||||
*/
|
||||
value: string
|
||||
/**
|
||||
* 租户名称
|
||||
*/
|
||||
label: string
|
||||
}
|
||||
|
||||
/** key value */
|
||||
export interface INumberEntry {
|
||||
/**
|
||||
* 租户ID
|
||||
*/
|
||||
value: number
|
||||
/**
|
||||
* 租户名称
|
||||
*/
|
||||
label: string
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { IBaseEntity, ISimpleTenant } from "./base"
|
||||
import { IBaseEntity, IStringEntry } from "./base"
|
||||
|
||||
/** 用户登录 */
|
||||
export interface ILoginData {
|
||||
@@ -268,5 +268,5 @@ export interface IUserListTenant {
|
||||
/**
|
||||
* 全部 租户信息
|
||||
*/
|
||||
all: ISimpleTenant[]
|
||||
all: IStringEntry[]
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import dayjs from "dayjs"
|
||||
import { removeConfigLayout } from "@/utils/cache/local-storage"
|
||||
import chinaAreaJson from "@/assets/ChinaArea.json"
|
||||
import { ISimpleProject, ISimpleTenant } from "@/types/base"
|
||||
import { CascaderOption } from "element-plus"
|
||||
|
||||
//#region 格式化日期时间
|
||||
export const DEFAULT_DATE_TIME_PATTERN = "YYYY-MM-DD HH:mm:ss"
|
||||
@@ -171,6 +172,26 @@ export const chinaAreaDeepQuery = (areaCode: number) => {
|
||||
return node
|
||||
}
|
||||
|
||||
/** 将权限树形结构扁平化为一维数组,用于权限查询 */
|
||||
export const flatTreeToCascaderOption = (arr: any[], { value = "id", label = "label", children = "children" }) => {
|
||||
const result: CascaderOption[] = []
|
||||
const deep = (arr1: any[], arr2: CascaderOption[]) => {
|
||||
arr1.forEach((item: any) => {
|
||||
const temp: CascaderOption = {
|
||||
value: item[value],
|
||||
label: item[label]
|
||||
}
|
||||
arr2.push(temp)
|
||||
if (item[children] && item[children].length > 0) {
|
||||
temp.children = []
|
||||
deep(item[children], temp.children)
|
||||
}
|
||||
})
|
||||
}
|
||||
deep(arr, result)
|
||||
return result
|
||||
}
|
||||
|
||||
// 未来的时间
|
||||
export const futureShortcuts = [
|
||||
{
|
||||
|
||||
@@ -148,27 +148,12 @@ import { treeDeptApi, saveDeptApi, updateDeptApi, deleteDeptApi } from "@/api/de
|
||||
import { IPmsDept } from "@/types/pms"
|
||||
import { ref, onMounted } from "vue"
|
||||
import { Plus, Edit, Delete, Sort } from "@element-plus/icons-vue"
|
||||
|
||||
import type { CascaderOption, CascaderValue } from "element-plus"
|
||||
import { ElMessage, ElMessageBox, FormInstance, FormRules, TableInstance } from "element-plus"
|
||||
import { isPhone } from "@/utils/validate"
|
||||
import { cloneDeep } from "lodash-es"
|
||||
import { showStringOverflow } from "@/hooks/useIndex"
|
||||
|
||||
// 部门
|
||||
export interface ISimplePmsDept {
|
||||
/**
|
||||
* 部门 ID
|
||||
*/
|
||||
value: number
|
||||
/**
|
||||
* 部门 名称
|
||||
*/
|
||||
label: string
|
||||
/**
|
||||
* 子部门
|
||||
*/
|
||||
children?: ISimplePmsDept[]
|
||||
}
|
||||
import { flatTreeToCascaderOption } from "@/utils"
|
||||
|
||||
/** 加载 */
|
||||
const loading = ref(false)
|
||||
@@ -221,26 +206,11 @@ const entityFormRules: FormRules = {
|
||||
}
|
||||
|
||||
// 上级权限
|
||||
const parentMenus = ref<ISimplePmsDept[]>()
|
||||
const parentMenus = ref<CascaderOption[]>()
|
||||
|
||||
/** 将权限树形结构扁平化为一维数组,用于权限查询 */
|
||||
const flatTree = (arr: IPmsDept[]) => {
|
||||
const result: ISimplePmsDept[] = []
|
||||
const deep = (arr1: IPmsDept[], arr2: ISimplePmsDept[]) => {
|
||||
arr1.forEach((item: IPmsDept) => {
|
||||
const temp: ISimplePmsDept = {
|
||||
value: item.deptId,
|
||||
label: item.deptName
|
||||
}
|
||||
arr2.push(temp)
|
||||
if (item.children && item.children.length > 0) {
|
||||
temp.children = []
|
||||
deep(item.children, temp.children)
|
||||
}
|
||||
})
|
||||
}
|
||||
deep(arr, result)
|
||||
return result
|
||||
const cascaderChange = (data: CascaderValue) => {
|
||||
const arr1 = data as number[]
|
||||
entityForm.value.parentId = arr1[arr1.length - 1]
|
||||
}
|
||||
|
||||
const expandAndCollapse = ref(true)
|
||||
@@ -265,7 +235,7 @@ const getTableData = () => {
|
||||
treeDeptApi()
|
||||
.then((resp) => {
|
||||
tableData.value = resp.data
|
||||
parentMenus.value = flatTree(resp.data)
|
||||
parentMenus.value = flatTreeToCascaderOption(resp.data, { value: "deptId", label: "deptName" })
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log("err :>> ", err)
|
||||
@@ -290,10 +260,6 @@ const resetEntity = () => {
|
||||
}
|
||||
}
|
||||
|
||||
const cascaderChange = (data: number[]) => {
|
||||
entityForm.value.parentId = data[data.length - 1]
|
||||
}
|
||||
|
||||
// 添加
|
||||
const handleAdd = (data: IPmsDept | null) => {
|
||||
resetEntity()
|
||||
|
||||
@@ -213,24 +213,15 @@ import { ISysMenu } from "@/types/pms"
|
||||
import { ref, onMounted } from "vue"
|
||||
import { Plus, Edit, Delete, Sort } from "@element-plus/icons-vue"
|
||||
import SvgIconSelect from "@/components/SvgIconSelect/index.vue"
|
||||
|
||||
import { ElMessage, ElMessageBox, FormInstance, FormRules, TableInstance } from "element-plus"
|
||||
|
||||
// 系统权限
|
||||
export interface ISimpleSysMenu {
|
||||
/**
|
||||
* 权限 ID
|
||||
*/
|
||||
value: number
|
||||
/**
|
||||
* 权限 名称
|
||||
*/
|
||||
label: string
|
||||
/**
|
||||
* 子权限
|
||||
*/
|
||||
children?: ISimpleSysMenu[]
|
||||
}
|
||||
import {
|
||||
ElMessage,
|
||||
ElMessageBox,
|
||||
FormInstance,
|
||||
FormRules,
|
||||
TableInstance,
|
||||
type CascaderOption,
|
||||
type CascaderValue
|
||||
} from "element-plus"
|
||||
|
||||
const dictStore = useDictStoreHook()
|
||||
|
||||
@@ -286,14 +277,14 @@ const entityFormRules: FormRules = {
|
||||
}
|
||||
|
||||
// 上级权限
|
||||
const parentMenus = ref<ISimpleSysMenu[]>()
|
||||
const parentMenus = ref<CascaderOption[]>()
|
||||
|
||||
/** 将权限树形结构扁平化为一维数组,用于权限查询 */
|
||||
const flatTree = (arr: ISysMenu[]) => {
|
||||
const result: ISimpleSysMenu[] = []
|
||||
const deep = (arr1: ISysMenu[], arr2: ISimpleSysMenu[]) => {
|
||||
const result: CascaderOption[] = []
|
||||
const deep = (arr1: ISysMenu[], arr2: CascaderOption[]) => {
|
||||
arr1.forEach((item: ISysMenu) => {
|
||||
const temp: ISimpleSysMenu = {
|
||||
const temp: CascaderOption = {
|
||||
value: item.menuId,
|
||||
label: item.menuName
|
||||
}
|
||||
@@ -308,6 +299,11 @@ const flatTree = (arr: ISysMenu[]) => {
|
||||
return result
|
||||
}
|
||||
|
||||
const cascaderChange = (data: CascaderValue) => {
|
||||
const arr1 = data as number[]
|
||||
entityForm.value.parentId = arr1[arr1.length - 1]
|
||||
}
|
||||
|
||||
const expandAndCollapse = ref(false)
|
||||
|
||||
// 展开和折叠
|
||||
@@ -331,7 +327,7 @@ const getTableData = () => {
|
||||
.then((resp) => {
|
||||
tableData.value = resp.data
|
||||
parentMenus.value = flatTree(resp.data)
|
||||
const temp: ISimpleSysMenu = {
|
||||
const temp: CascaderOption = {
|
||||
value: 0,
|
||||
label: "顶级权限"
|
||||
}
|
||||
@@ -364,10 +360,6 @@ const resetEntity = () => {
|
||||
}
|
||||
}
|
||||
|
||||
const cascaderChange = (data: number[]) => {
|
||||
entityForm.value.parentId = data[data.length - 1]
|
||||
}
|
||||
|
||||
// 添加
|
||||
const handleAdd = (data: ISysMenu | null) => {
|
||||
resetEntity()
|
||||
|
||||
@@ -301,7 +301,6 @@ import {
|
||||
} from "@/api/user"
|
||||
import { treeDeptApi } from "@/api/dept"
|
||||
import { listRoleApi } from "@/api/role"
|
||||
import { ISimpleTenant } from "@/types/base"
|
||||
import { IPmsUser, IPmsDept, IPmsRole } from "@/types/pms"
|
||||
import UserAvatar from "@/components/UserAvatar/index.vue"
|
||||
import UserLoginLog from "@/components/UserLoginLog/index.vue"
|
||||
@@ -314,6 +313,7 @@ import { useTenantStoreHook } from "@/store/modules/tenant"
|
||||
import { futureShortcuts } from "@/utils"
|
||||
import { showExpiredDateAgo, showStringOverflow } from "@/hooks/useIndex"
|
||||
import { cloneDeep } from "lodash-es"
|
||||
import { IStringEntry } from "@/types/base"
|
||||
|
||||
// 判读 当前选中的租户是否 默认租户
|
||||
const { isDefaultTenantId } = useTenantStoreHook()
|
||||
@@ -679,7 +679,7 @@ interface LinkTenant {
|
||||
visible: boolean
|
||||
title: string
|
||||
userId: number
|
||||
all: ISimpleTenant[]
|
||||
all: IStringEntry[]
|
||||
have: string[]
|
||||
}
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ public class SysTemplateServiceImpl extends BaseServiceImpl<SysTemplateMapper, S
|
||||
throw new RuntimeException(String.format("模板ID %d 不存在!", templateId));
|
||||
}
|
||||
baseMapper.deleteHaveMenus(templateId);
|
||||
if (menus != null && menus.size() > 0) {
|
||||
if (menus != null && !menus.isEmpty()) {
|
||||
return baseMapper.insertByMenus(templateId, menus) > 0;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
<template>
|
||||
<el-cascader v-model="result" :options="props.options" :props="cascaderProps" filterable clearable />
|
||||
<el-cascader v-model="result" :options="cascaderOptions" :props="{ checkStrictly: true }" filterable clearable />
|
||||
</template>
|
||||
|
||||
<script setup lang="ts" name="CascaderDept">
|
||||
import { computed } from "vue"
|
||||
import { IPmsDept } from "@/types/pms"
|
||||
import type { CascaderValue } from "element-plus"
|
||||
import { flatTreeToCascaderOption } from "@/utils"
|
||||
|
||||
const props = defineProps({
|
||||
modelValue: {
|
||||
type: Number,
|
||||
@@ -16,17 +19,18 @@ const props = defineProps({
|
||||
}
|
||||
})
|
||||
|
||||
const cascaderProps = { checkStrictly: true, value: "deptId", label: "deptName" }
|
||||
const cascaderOptions = flatTreeToCascaderOption(props.options, { value: "deptId", label: "deptName" })
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: "update:modelValue", value: Number): void
|
||||
}>()
|
||||
|
||||
const result = computed({
|
||||
get(): Number {
|
||||
get(): CascaderValue {
|
||||
return props.modelValue
|
||||
},
|
||||
set(val: Number[]) {
|
||||
set(data: CascaderValue) {
|
||||
const val = data as number[]
|
||||
if (val && val.length > 0) {
|
||||
const v1 = val[val.length - 1]
|
||||
emit("update:modelValue", v1)
|
||||
|
||||
@@ -54,14 +54,14 @@ const props = defineProps({
|
||||
})
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: "update:value", value: String): void
|
||||
(e: "update:value", value: string): void
|
||||
}>()
|
||||
|
||||
const result = computed({
|
||||
get(): String {
|
||||
get(): string {
|
||||
return props.value
|
||||
},
|
||||
set(v: String) {
|
||||
set(v: string) {
|
||||
emit("update:value", v)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -2,6 +2,7 @@ import dayjs from "dayjs"
|
||||
import { removeConfigLayout } from "@/utils/cache/local-storage"
|
||||
import chinaAreaJson from "@/assets/ChinaArea.json"
|
||||
import { ISimpleProject } from "@/types/base"
|
||||
import { CascaderOption } from "element-plus"
|
||||
|
||||
//#region 格式化日期时间
|
||||
export const DEFAULT_DATE_TIME_PATTERN = "YYYY-MM-DD HH:mm:ss"
|
||||
@@ -171,6 +172,26 @@ export const chinaAreaDeepQuery = (areaCode: number) => {
|
||||
return node
|
||||
}
|
||||
|
||||
/** 将权限树形结构扁平化为一维数组,用于权限查询 */
|
||||
export const flatTreeToCascaderOption = (arr: any[], { value = "id", label = "label", children = "children" }) => {
|
||||
const result: CascaderOption[] = []
|
||||
const deep = (arr1: any[], arr2: CascaderOption[]) => {
|
||||
arr1.forEach((item: any) => {
|
||||
const temp: CascaderOption = {
|
||||
value: item[value],
|
||||
label: item[label]
|
||||
}
|
||||
arr2.push(temp)
|
||||
if (item[children] && item[children].length > 0) {
|
||||
temp.children = []
|
||||
deep(item[children], temp.children)
|
||||
}
|
||||
})
|
||||
}
|
||||
deep(arr, result)
|
||||
return result
|
||||
}
|
||||
|
||||
// 未来的时间
|
||||
export const futureShortcuts = [
|
||||
{
|
||||
|
||||
@@ -148,27 +148,12 @@ import { treeDeptApi, saveDeptApi, updateDeptApi, deleteDeptApi } from "@/api/de
|
||||
import { IPmsDept } from "@/types/pms"
|
||||
import { ref, onMounted } from "vue"
|
||||
import { Plus, Edit, Delete, Sort } from "@element-plus/icons-vue"
|
||||
|
||||
import type { CascaderOption, CascaderValue } from "element-plus"
|
||||
import { ElMessage, ElMessageBox, FormInstance, FormRules, TableInstance } from "element-plus"
|
||||
import { isPhone } from "@/utils/validate"
|
||||
import { cloneDeep } from "lodash-es"
|
||||
import { showStringOverflow } from "@/hooks/useIndex"
|
||||
|
||||
// 部门
|
||||
export interface ISimplePmsDept {
|
||||
/**
|
||||
* 部门 ID
|
||||
*/
|
||||
value: number
|
||||
/**
|
||||
* 部门 名称
|
||||
*/
|
||||
label: string
|
||||
/**
|
||||
* 子部门
|
||||
*/
|
||||
children?: ISimplePmsDept[]
|
||||
}
|
||||
import { flatTreeToCascaderOption } from "@/utils"
|
||||
|
||||
/** 加载 */
|
||||
const loading = ref(false)
|
||||
@@ -221,26 +206,11 @@ const entityFormRules: FormRules = {
|
||||
}
|
||||
|
||||
// 上级权限
|
||||
const parentMenus = ref<ISimplePmsDept[]>()
|
||||
const parentMenus = ref<CascaderOption[]>()
|
||||
|
||||
/** 将权限树形结构扁平化为一维数组,用于权限查询 */
|
||||
const flatTree = (arr: IPmsDept[]) => {
|
||||
const result: ISimplePmsDept[] = []
|
||||
const deep = (arr1: IPmsDept[], arr2: ISimplePmsDept[]) => {
|
||||
arr1.forEach((item: IPmsDept) => {
|
||||
const temp: ISimplePmsDept = {
|
||||
value: item.deptId,
|
||||
label: item.deptName
|
||||
}
|
||||
arr2.push(temp)
|
||||
if (item.children && item.children.length > 0) {
|
||||
temp.children = []
|
||||
deep(item.children, temp.children)
|
||||
}
|
||||
})
|
||||
}
|
||||
deep(arr, result)
|
||||
return result
|
||||
const cascaderChange = (data: CascaderValue) => {
|
||||
const arr1 = data as number[]
|
||||
entityForm.value.parentId = arr1[arr1.length - 1]
|
||||
}
|
||||
|
||||
const expandAndCollapse = ref(true)
|
||||
@@ -265,7 +235,7 @@ const getTableData = () => {
|
||||
treeDeptApi()
|
||||
.then((resp) => {
|
||||
tableData.value = resp.data
|
||||
parentMenus.value = flatTree(resp.data)
|
||||
parentMenus.value = flatTreeToCascaderOption(resp.data, { value: "deptId", label: "deptName" })
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log("err :>> ", err)
|
||||
@@ -290,10 +260,6 @@ const resetEntity = () => {
|
||||
}
|
||||
}
|
||||
|
||||
const cascaderChange = (data: number[]) => {
|
||||
entityForm.value.parentId = data[data.length - 1]
|
||||
}
|
||||
|
||||
// 添加
|
||||
const handleAdd = (data: IPmsDept | null) => {
|
||||
resetEntity()
|
||||
|
||||
@@ -213,25 +213,10 @@ import { ISysMenu } from "@/types/pms"
|
||||
import { ref, onMounted } from "vue"
|
||||
import { Plus, Edit, Delete, Sort } from "@element-plus/icons-vue"
|
||||
import SvgIconSelect from "@/components/SvgIconSelect/index.vue"
|
||||
import type { CascaderOption, CascaderValue } from "element-plus"
|
||||
|
||||
import { ElMessage, ElMessageBox, FormInstance, FormRules, TableInstance } from "element-plus"
|
||||
|
||||
// 系统权限
|
||||
export interface ISimpleSysMenu {
|
||||
/**
|
||||
* 权限 ID
|
||||
*/
|
||||
value: number
|
||||
/**
|
||||
* 权限 名称
|
||||
*/
|
||||
label: string
|
||||
/**
|
||||
* 子权限
|
||||
*/
|
||||
children?: ISimpleSysMenu[]
|
||||
}
|
||||
|
||||
const dictStore = useDictStoreHook()
|
||||
|
||||
/** 加载 */
|
||||
@@ -286,14 +271,14 @@ const entityFormRules: FormRules = {
|
||||
}
|
||||
|
||||
// 上级权限
|
||||
const parentMenus = ref<ISimpleSysMenu[]>()
|
||||
const parentMenus = ref<CascaderOption[]>()
|
||||
|
||||
/** 将权限树形结构扁平化为一维数组,用于权限查询 */
|
||||
const flatTree = (arr: ISysMenu[]) => {
|
||||
const result: ISimpleSysMenu[] = []
|
||||
const deep = (arr1: ISysMenu[], arr2: ISimpleSysMenu[]) => {
|
||||
const result: CascaderOption[] = []
|
||||
const deep = (arr1: ISysMenu[], arr2: CascaderOption[]) => {
|
||||
arr1.forEach((item: ISysMenu) => {
|
||||
const temp: ISimpleSysMenu = {
|
||||
const temp: CascaderOption = {
|
||||
value: item.menuId,
|
||||
label: item.menuName
|
||||
}
|
||||
@@ -308,6 +293,11 @@ const flatTree = (arr: ISysMenu[]) => {
|
||||
return result
|
||||
}
|
||||
|
||||
const cascaderChange = (data: CascaderValue) => {
|
||||
const arr1 = data as number[]
|
||||
entityForm.value.parentId = arr1[arr1.length - 1]
|
||||
}
|
||||
|
||||
const expandAndCollapse = ref(false)
|
||||
|
||||
// 展开和折叠
|
||||
@@ -331,7 +321,7 @@ const getTableData = () => {
|
||||
.then((resp) => {
|
||||
tableData.value = resp.data
|
||||
parentMenus.value = flatTree(resp.data)
|
||||
const temp: ISimpleSysMenu = {
|
||||
const temp: CascaderOption = {
|
||||
value: 0,
|
||||
label: "顶级权限"
|
||||
}
|
||||
@@ -364,10 +354,6 @@ const resetEntity = () => {
|
||||
}
|
||||
}
|
||||
|
||||
const cascaderChange = (data: number[]) => {
|
||||
entityForm.value.parentId = data[data.length - 1]
|
||||
}
|
||||
|
||||
// 添加
|
||||
const handleAdd = (data: ISysMenu | null) => {
|
||||
resetEntity()
|
||||
|
||||
Reference in New Issue
Block a user