添加字典模块

This commit is contained in:
icssoa 2022-07-06 12:35:16 +08:00
parent 4d0064fafd
commit ce3d0a7e06
16 changed files with 1672 additions and 524 deletions

View File

@ -0,0 +1,507 @@
declare interface BaseSysDepartmentEntity {
/**
* ID
*/
id?: number;
/**
*
*/
name?: string;
/**
* ID
*/
parentId?: BigInt;
/**
*
*/
orderNum?: number;
/**
*
*/
createTime?: Date;
/**
*
*/
updateTime?: Date;
/**
*
*/
[key: string]: any;
}
declare interface BaseSysLogEntity {
/**
* ID
*/
id?: number;
/**
* ID
*/
userId?: BigInt;
/**
*
*/
action?: string;
/**
* ip
*/
ip?: string;
/**
* ip地址
*/
ipAddr?: string;
/**
*
*/
params?: string;
/**
*
*/
createTime?: Date;
/**
*
*/
updateTime?: Date;
/**
*
*/
[key: string]: any;
}
declare interface BaseSysMenuEntity {
/**
* ID
*/
id?: number;
/**
* ID
*/
parentId?: BigInt;
/**
*
*/
name?: string;
/**
*
*/
router?: string;
/**
*
*/
perms?: string;
/**
* 0 1 2
*/
type?: number;
/**
*
*/
icon?: string;
/**
*
*/
orderNum?: number;
/**
*
*/
viewPath?: string;
/**
*
*/
keepAlive?: boolean;
/**
*
*/
isShow?: boolean;
/**
*
*/
createTime?: Date;
/**
*
*/
updateTime?: Date;
/**
*
*/
[key: string]: any;
}
declare interface BaseSysParamEntity {
/**
* ID
*/
id?: number;
/**
*
*/
keyName?: string;
/**
*
*/
name?: string;
/**
*
*/
data?: string;
/**
* 0:字符串 1 2
*/
dataType?: number;
/**
*
*/
remark?: string;
/**
*
*/
createTime?: Date;
/**
*
*/
updateTime?: Date;
/**
*
*/
[key: string]: any;
}
declare interface BaseSysRoleEntity {
/**
* ID
*/
id?: number;
/**
* ID
*/
userId?: string;
/**
*
*/
name?: string;
/**
*
*/
label?: string;
/**
*
*/
remark?: string;
/**
*
*/
relevance?: number;
/**
*
*/
createTime?: Date;
/**
*
*/
updateTime?: Date;
/**
*
*/
[key: string]: any;
}
declare interface BaseSysUserEntity {
/**
* ID
*/
id?: number;
/**
* ID
*/
departmentId?: BigInt;
/**
*
*/
name?: string;
/**
*
*/
username?: string;
/**
*
*/
password?: string;
/**
* , token失效
*/
passwordV?: number;
/**
*
*/
nickName?: string;
/**
*
*/
headImg?: string;
/**
*
*/
phone?: string;
/**
*
*/
email?: string;
/**
*
*/
remark?: string;
/**
* 0:禁用 1
*/
status?: boolean;
/**
* socketId
*/
socketId?: string;
/**
*
*/
createTime?: Date;
/**
*
*/
updateTime?: Date;
/**
*
*/
[key: string]: any;
}
declare interface DemoGoodsEntity {
/**
* ID
*/
id?: number;
/**
*
*/
title?: string;
/**
*
*/
pic?: string;
/**
*
*/
price?: number;
/**
*
*/
type?: number;
/**
*
*/
createTime?: Date;
/**
*
*/
updateTime?: Date;
/**
*
*/
[key: string]: any;
}
declare interface DictInfoEntity {
/**
* ID
*/
id?: number;
/**
* ID
*/
typeId?: number;
/**
*
*/
name?: string;
/**
*
*/
orderNum?: number;
/**
*
*/
remark?: string;
/**
*
*/
createTime?: Date;
/**
*
*/
updateTime?: Date;
/**
*
*/
[key: string]: any;
}
declare interface DictTypeEntity {
/**
* ID
*/
id?: number;
/**
*
*/
name?: string;
/**
*
*/
key?: string;
/**
*
*/
createTime?: Date;
/**
*
*/
updateTime?: Date;
/**
*
*/
[key: string]: any;
}
declare interface SpaceInfoEntity {
/**
* ID
*/
id?: number;
/**
*
*/
url?: string;
/**
*
*/
type?: string;
/**
* ID
*/
classifyId?: BigInt;
/**
*
*/
createTime?: Date;
/**
*
*/
updateTime?: Date;
/**
*
*/
[key: string]: any;
}
declare interface SpaceTypeEntity {
/**
* ID
*/
id?: number;
/**
*
*/
name?: string;
/**
* ID
*/
parentId?: number;
/**
*
*/
createTime?: Date;
/**
*
*/
updateTime?: Date;
/**
*
*/
[key: string]: any;
}
declare interface TaskInfoEntity {
/**
* ID
*/
id?: number;
/**
* ID
*/
jobId?: string;
/**
*
*/
repeatConf?: string;
/**
*
*/
name?: string;
/**
* cron
*/
cron?: string;
/**
*
*/
limit?: number;
/**
* cron设置了
*/
every?: number;
/**
*
*/
remark?: string;
/**
* 0:停止 1
*/
status?: boolean;
/**
*
*/
startDate?: Date;
/**
*
*/
endDate?: Date;
/**
*
*/
data?: string;
/**
* service实例ID
*/
service?: string;
/**
* 0:系统 1
*/
type?: number;
/**
*
*/
nextRunTime?: Date;
/**
* 0:cron 1
*/
taskType?: number;
/**
*
*/
createTime?: Date;
/**
*
*/
updateTime?: Date;
/**
*
*/
[key: string]: any;
}

View File

@ -1 +1 @@
[["/admin/base/comm",[["","/list",""],["","/page",""],["","/info",""],["","/update",""],["","/delete",""],["","/add",""],["","/personUpdate",""],["","/uploadMode",""],["","/permmenu",""],["","/logout",""]]],["/admin/base/open",[["","/list",""],["","/page",""],["","/info",""],["","/update",""],["","/delete",""],["","/add",""],["","/refreshToken",""],["","/captcha",""],["","/login",""],["","/html",""],["","/eps",""]]],["/admin/base/sys/department",[["","/list",""],["","/page",""],["","/info",""],["","/update",""],["","/delete",""],["","/add",""],["","/order",""]]],["/admin/base/sys/log",[["","/list",""],["","/page",""],["","/info",""],["","/update",""],["","/delete",""],["","/add",""],["","/setKeep",""],["","/getKeep",""],["","/clear",""]]],["/admin/base/sys/menu",[["","/list",""],["","/page",""],["","/info",""],["","/update",""],["","/delete",""],["","/add",""]]],["/admin/base/sys/param",[["","/list",""],["","/page",""],["","/info",""],["","/update",""],["","/delete",""],["","/add",""],["","/html",""]]],["/admin/base/sys/role",[["","/list",""],["","/page",""],["","/info",""],["","/update",""],["","/delete",""],["","/add",""]]],["/admin/base/sys/user",[["","/list",""],["","/page",""],["","/info",""],["","/update",""],["","/delete",""],["","/add",""],["","/move",""]]],["/admin/demo/goods",[["","/list",""],["","/page",""],["","/info",""],["","/update",""],["","/delete",""],["","/add",""]]],["/admin/space/info",[["","/list",""],["","/page",""],["","/info",""],["","/update",""],["","/delete",""],["","/add",""]]],["/admin/space/type",[["","/list",""],["","/page",""],["","/info",""],["","/update",""],["","/delete",""],["","/add",""]]],["/admin/task/info",[["","/list",""],["","/page",""],["","/info",""],["","/update",""],["","/delete",""],["","/add",""],["","/start",""],["","/once",""],["","/stop",""],["","/log",""]]],["/chat/message",[["","/list",""],["","/page",""],["","/info",""],["","/update",""],["","/delete",""],["","/add",""]]],["/chat/session",[["","/list",""],["","/page",""],["","/info",""],["","/update",""],["","/delete",""],["","/add",""]]],["/test",[["","/list",""],["","/page",""],["","/info",""],["","/update",""],["","/delete",""],["","/add",""]]]] [["/admin/base/comm",[["post","/personUpdate",""],["get","/uploadMode",""],["get","/permmenu",""],["get","/person",""],["post","/upload",""],["post","/logout",""],["","/list",""],["","/page",""],["","/info",""],["","/update",""],["","/delete",""],["","/add",""]]],["/admin/base/open",[["get","/refreshToken",""],["get","/captcha",""],["post","/login",""],["get","/html",""],["get","/eps",""],["","/list",""],["","/page",""],["","/info",""],["","/update",""],["","/delete",""],["","/add",""]]],["/admin/base/sys/department",[["post","/delete",""],["post","/update",""],["post","/order",""],["post","/list",""],["post","/add",""],["","/page",""],["","/info",""]]],["/admin/base/sys/log",[["post","/setKeep",""],["get","/getKeep",""],["post","/clear",""],["post","/page",""],["","/list",""],["","/info",""],["","/update",""],["","/delete",""],["","/add",""]]],["/admin/base/sys/menu",[["post","/delete",""],["post","/update",""],["get","/info",""],["post","/list",""],["post","/page",""],["post","/add",""]]],["/admin/base/sys/param",[["post","/delete",""],["post","/update",""],["get","/html",""],["get","/info",""],["post","/page",""],["post","/add",""],["","/list",""]]],["/admin/base/sys/role",[["post","/delete",""],["post","/update",""],["get","/info",""],["post","/list",""],["post","/page",""],["post","/add",""]]],["/admin/base/sys/user",[["post","/delete",""],["post","/update",""],["post","/move",""],["get","/info",""],["post","/list",""],["post","/page",""],["post","/add",""]]],["/admin/demo/goods",[["post","/delete",""],["post","/update",""],["get","/info",""],["post","/page",""],["post","/list",""],["post","/add",""]]],["/admin/dict/info",[["post","/delete",""],["post","/update",""],["post","/data",""],["get","/info",""],["post","/list",""],["post","/page",""],["post","/add",""]]],["/admin/dict/type",[["post","/delete",""],["post","/update",""],["get","/info",""],["post","/list",""],["post","/page",""],["post","/add",""]]],["/admin/space/info",[["post","/delete",""],["post","/update",""],["get","/info",""],["post","/list",""],["post","/page",""],["post","/add",""]]],["/admin/space/type",[["post","/delete",""],["post","/update",""],["get","/info",""],["post","/list",""],["post","/page",""],["post","/add",""]]],["/admin/task/info",[["post","/delete",""],["post","/update",""],["post","/start",""],["post","/once",""],["post","/stop",""],["get","/info",""],["post","/page",""],["get","/log",""],["post","/add",""],["","/list",""]]],["/chat/message",[["","/list",""],["","/page",""],["","/info",""],["","/update",""],["","/delete",""],["","/add",""]]],["/chat/session",[["","/list",""],["","/page",""],["","/info",""],["","/update",""],["","/delete",""],["","/add",""]]],["/test",[["","/list",""],["","/page",""],["","/info",""],["","/update",""],["","/delete",""],["","/add",""]]]]

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "front-next", "name": "front-next",
"version": "5.5.1", "version": "5.6.0",
"scripts": { "scripts": {
"dev": "vite --host", "dev": "vite --host",
"build": "vite build", "build": "vite build",
@ -9,7 +9,7 @@
"lint:eslint": "eslint \"{src,mock}/**/*.{vue,ts,tsx}\" --fix" "lint:eslint": "eslint \"{src,mock}/**/*.{vue,ts,tsx}\" --fix"
}, },
"dependencies": { "dependencies": {
"@cool-vue/crud": "^5.2.7", "@cool-vue/crud": "^5.2.10",
"@element-plus/icons-vue": "^1.1.3", "@element-plus/icons-vue": "^1.1.3",
"@vueuse/core": "^8.2.5", "@vueuse/core": "^8.2.5",
"axios": "^0.27.2", "axios": "^0.27.2",

View File

@ -8,6 +8,7 @@ import VueECharts from "vue-echarts";
import ElementPlus from "element-plus"; import ElementPlus from "element-plus";
import "element-plus/theme-chalk/src/index.scss"; import "element-plus/theme-chalk/src/index.scss";
import "uno.css"; import "uno.css";
import { useDict } from "/$/dict";
export async function bootstrap(Vue: App) { export async function bootstrap(Vue: App) {
// 缓存 // 缓存
@ -38,6 +39,12 @@ export async function bootstrap(Vue: App) {
app.showLoading(); app.showLoading();
if (user.token) { if (user.token) {
// 字典
const { dict } = useDict();
// 获取字典数据
dict.refresh();
// 获取用户信息 // 获取用户信息
user.get(); user.get();

View File

@ -1,5 +1,5 @@
import { useStore } from "../store"; import { useStore } from "../store";
import { isObject } from "lodash"; import { isArray, isObject } from "lodash";
function parse(value: any) { function parse(value: any) {
const { menu } = useStore(); const { menu } = useStore();
@ -28,3 +28,15 @@ export function checkPerm(value: any) {
return parse(value); return parse(value);
} }
export function getPerm(service: any, names: string[] | string) {
if (!service._permission) {
return false;
}
if (!isArray(names)) {
names = [names];
}
return !names.find((e) => !service._permission[e]);
}

View File

@ -1,7 +1,7 @@
<template> <template>
<el-select v-model="value" @change="onChange" clearable> <el-select v-model="value" @change="onChange" clearable>
<el-option <el-option
v-for="(item, index) in options" v-for="(item, index) in list"
:key="index" :key="index"
:label="item.label" :label="item.label"
:value="item.value" :value="item.value"
@ -11,7 +11,7 @@
<script lang="ts"> <script lang="ts">
import { useCrud } from "@cool-vue/crud"; import { useCrud } from "@cool-vue/crud";
import { defineComponent, PropType, ref, watch } from "vue"; import { computed, defineComponent, isRef, ref, watch } from "vue";
export default defineComponent({ export default defineComponent({
name: "cl-select", name: "cl-select",
@ -19,7 +19,7 @@ export default defineComponent({
props: { props: {
modelValue: [String, Number], modelValue: [String, Number],
options: { options: {
type: Array as PropType<Array<{ label: string; value: any }>>, type: Array,
default: () => [] default: () => []
}, },
prop: String prop: String
@ -31,6 +31,9 @@ export default defineComponent({
// cl-crud // cl-crud
const Crud = useCrud(); const Crud = useCrud();
const value = ref(); const value = ref();
const list = computed<any>(() =>
isRef(props.options) ? props.options.value : props.options
);
// //
function onChange(val: string) { function onChange(val: string) {
@ -53,6 +56,7 @@ export default defineComponent({
); );
return { return {
list,
value, value,
onChange onChange
}; };

View File

@ -0,0 +1,154 @@
<template>
<div class="cl-view-group">
<div class="cl-view-group__wrap">
<!-- -->
<div class="cl-view-group__left" :class="[isExpand ? '_expand' : '_collapse']">
<slot name="left"></slot>
</div>
<!-- 内容 -->
<div class="cl-view-group__right">
<div class="cl-view-group__right-head">
<div class="icon" @click="toExpand()">
<el-icon v-if="isExpand"><arrow-left /></el-icon>
<el-icon v-else><arrow-right /></el-icon>
</div>
<span>{{ title }}</span>
</div>
<div class="cl-view-group__right-content">
<slot name="right"></slot>
</div>
</div>
</div>
</div>
</template>
<script lang="ts">
import { defineComponent, ref, watch } from "vue";
import { ArrowLeft, ArrowRight } from "@element-plus/icons-vue";
import { useBase } from "/$/base";
export default defineComponent({
name: "cl-view-group",
components: {
ArrowLeft,
ArrowRight
},
props: {
title: String
},
setup() {
const { app } = useBase();
//
const isExpand = ref<boolean>(true);
//
function toExpand(value?: boolean) {
isExpand.value = value === undefined ? !isExpand.value : value;
}
//
function checkExpand(value?: boolean) {
if (app.browser.isMini) {
toExpand(value);
}
}
//
watch(
() => app.browser.isMini,
(val: boolean) => {
isExpand.value = !val;
},
{
immediate: true
}
);
return {
isExpand,
toExpand,
checkExpand,
app
};
}
});
</script>
<style lang="scss" scoped>
.cl-view-group {
height: 100%;
width: 100%;
&__wrap {
display: flex;
height: 100%;
width: 100%;
position: relative;
}
&__left {
height: 100%;
width: 300px;
max-width: calc(100% - 50px);
background-color: #fff;
transition: width 0.3s;
margin-right: 10px;
flex-shrink: 0;
overflow: hidden;
&._collapse {
margin-right: 0;
width: 0;
}
}
&__right {
width: calc(100% - 310px);
flex: 1;
overflow: hidden;
&-head {
display: flex;
align-items: center;
justify-content: center;
height: 40px;
position: relative;
background-color: #fff;
span {
font-size: 14px;
white-space: nowrap;
overflow: hidden;
}
.icon {
display: flex;
align-items: center;
position: absolute;
left: 0;
top: 0;
font-size: 18px;
cursor: pointer;
background-color: #fff;
height: 40px;
width: 80px;
padding-left: 10px;
}
}
&-content {
height: calc(100% - 40px);
}
}
@media only screen and (max-width: 768px) {
.cl-view-group__right {
width: calc(100% - 100px);
}
}
}
</style>

View File

@ -1,23 +1,10 @@
<template> <template>
<div class="view-user"> <cl-view-group :ref="setRefs('viewGroup')" :title="title">
<div class="pane"> <template #left>
<!-- 组织架构 -->
<div class="dept" :class="[isExpand ? '_expand' : '_collapse']">
<dept-tree @row-click="onDeptRowClick" @user-add="onDeptUserAdd" /> <dept-tree @row-click="onDeptRowClick" @user-add="onDeptUserAdd" />
</div> </template>
<!-- 成员列表 --> <template #right>
<div class="user">
<div class="user__header">
<div class="icon" @click="deptExpand">
<el-icon v-if="isExpand"><arrow-left /></el-icon>
<el-icon v-else><arrow-right /></el-icon>
</div>
<span>成员列表{{ selects.dept?.name }}</span>
</div>
<div class="user__container">
<cl-crud ref="Crud"> <cl-crud ref="Crud">
<el-row> <el-row>
<cl-refresh-btn /> <cl-refresh-btn />
@ -79,22 +66,19 @@
<cl-upsert ref="Upsert" /> <cl-upsert ref="Upsert" />
<dept-move-form ref="DeptMove" /> <dept-move-form ref="DeptMove" />
</cl-crud> </cl-crud>
</div> </template>
</div> </cl-view-group>
</div>
</div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { useTable, useUpsert, useCrud } from "@cool-vue/crud"; import { useTable, useUpsert, useCrud } from "@cool-vue/crud";
import { reactive, ref, watch } from "vue"; import { computed, reactive, ref } from "vue";
import { ArrowLeft, ArrowRight } from "@element-plus/icons-vue";
import { useCool } from "/@/cool"; import { useCool } from "/@/cool";
import { useBase } from "/$/base"; import { useBase } from "/$/base";
import DeptMoveForm from "./components/dept-move"; import DeptMoveForm from "./components/dept-move";
import DeptTree from "./components/dept-tree.vue"; import DeptTree from "./components/dept-tree.vue";
const { service } = useCool(); const { service, refs, setRefs } = useCool();
const { app } = useBase(); const { app } = useBase();
const DeptMove = ref<any>(); const DeptMove = ref<any>();
@ -108,6 +92,11 @@ const selects = reactive<any>({
ids: [] ids: []
}); });
//
const title = computed(() => {
return `成员列表(${selects.dept?.name || ""}`;
});
// cl-crud // cl-crud
const Crud = useCrud({ const Crud = useCrud({
service: service.base.sys.user service: service.base.sys.user
@ -361,9 +350,7 @@ function onDeptRowClick({ item, ids }: any) {
}); });
// //
if (app.browser.isMini) { refs.value.viewGroup.checkExpand(false);
isExpand.value = false;
}
} }
// //
@ -373,11 +360,6 @@ function onDeptUserAdd(item: any) {
}); });
} }
//
function deptExpand() {
isExpand.value = !isExpand.value;
}
// //
async function toMove(e?: any) { async function toMove(e?: any) {
let ids = []; let ids = [];
@ -390,89 +372,4 @@ async function toMove(e?: any) {
DeptMove.value.toMove(ids); DeptMove.value.toMove(ids);
} }
//
watch(
() => app.browser.isMini,
(val: boolean) => {
isExpand.value = !val;
},
{
immediate: true
}
);
</script> </script>
<style lang="scss" scoped>
.view-user {
.pane {
display: flex;
height: 100%;
width: 100%;
position: relative;
}
.dept {
height: 100%;
width: 300px;
max-width: calc(100% - 50px);
background-color: #fff;
transition: width 0.3s;
margin-right: 10px;
flex-shrink: 0;
&._collapse {
margin-right: 0;
width: 0;
}
}
.user {
width: calc(100% - 310px);
flex: 1;
&__header {
display: flex;
align-items: center;
justify-content: center;
height: 40px;
position: relative;
background-color: #fff;
span {
font-size: 14px;
white-space: nowrap;
overflow: hidden;
}
.icon {
display: flex;
align-items: center;
position: absolute;
left: 0;
top: 0;
font-size: 18px;
cursor: pointer;
background-color: #fff;
height: 40px;
width: 80px;
padding-left: 10px;
}
}
}
.dept,
.user {
overflow: hidden;
&__container {
height: calc(100% - 40px);
}
}
@media only screen and (max-width: 768px) {
.dept {
width: calc(100% - 100px);
}
}
}
</style>

View File

@ -6,6 +6,10 @@
<cl-add-btn /> <cl-add-btn />
<el-button @click="openForm">自定义表单</el-button> <el-button @click="openForm">自定义表单</el-button>
<cl-filter label="字典">
<cl-select :options="dict.get('sex')"></cl-select>
</cl-filter>
<cl-flex1></cl-flex1> <cl-flex1></cl-flex1>
<cl-column-custom :columns="Table?.columns" /> <cl-column-custom :columns="Table?.columns" />
<cl-filter-group :items="filter.items"></cl-filter-group> <cl-filter-group :items="filter.items"></cl-filter-group>
@ -44,6 +48,11 @@
<script lang="tsx" setup> <script lang="tsx" setup>
import { useCrud, useUpsert, useTable, useForm, useAdvSearch } from "@cool-vue/crud"; import { useCrud, useUpsert, useTable, useForm, useAdvSearch } from "@cool-vue/crud";
import { useDict } from "/$/dict";
const { dict } = useDict();
dict.refresh(["sex"]);
const Crud = useCrud( const Crud = useCrud(
{ {
@ -64,6 +73,14 @@ const Upsert = useUpsert({
name: "el-input" name: "el-input"
} }
}, },
{
label: "认证类型",
prop: "authType",
component: {
name: "el-select",
options: dict.get("authType")
}
},
{ {
type: "tabs", type: "tabs",
props: { props: {

View File

@ -0,0 +1,255 @@
<template>
<div class="dict-group" v-loading="loading">
<div class="head">
<span>类型</span>
<el-button
type="success"
bg
size="small"
v-if="getPerm(service.dict.type, 'add')"
@click="edit()"
>添加</el-button
>
</div>
<ul class="scroller1">
<li
v-for="(item, index) in list"
:key="index"
class="item"
:class="{
'is-active': active == item.id
}"
@click="select(item)"
@contextmenu="
(e) => {
onContextMenu(e, item);
}
"
>
<span>{{ item.name }} - {{ item.key }}</span>
<el-icon v-show="active == item.id"><ArrowRightBold /></el-icon>
</li>
<el-empty v-if="list.length == 0" :image-size="80" />
</ul>
<!-- 表单 -->
<cl-form ref="Form"></cl-form>
</div>
</template>
<script lang="ts" setup>
import { ContextMenu, useForm } from "@cool-vue/crud";
import { ElMessage, ElMessageBox } from "element-plus";
import { inject, onMounted, ref } from "vue";
import { useCool } from "/@/cool";
import { ArrowRightBold } from "@element-plus/icons-vue";
import { getPerm } from "/$/base";
const { service } = useCool();
const Form = useForm();
//
const dict = inject<any>("dict");
//
const active = ref("");
//
const list = ref<any[]>([]);
//
const loading = ref(false);
//
async function refresh() {
loading.value = true;
await service.dict.type.list().then((res) => {
list.value = res;
if (!active.value) {
select(res[0]);
}
});
loading.value = false;
}
//
function select(item: any) {
active.value = item?.id;
//
dict.setGroup(item);
//
dict.refresh({
typeId: active.value,
page: 1
});
}
//
function edit(item?: any) {
Form.value?.open({
title: item ? "编辑类型" : "添加类型",
width: "500px",
items: [
{
label: "名称",
prop: "name",
component: {
name: "el-input",
props: {
maxlength: 20
}
},
required: true
},
{
label: "Key",
prop: "key",
component: {
name: "el-input",
props: {
maxlength: 20
}
},
required: true
}
],
form: {
...item
},
on: {
submit(data, { close, done }) {
service.dict.type[item ? "update" : "add"](data)
.then(() => {
ElMessage.success("保存成功");
close();
refresh();
})
.catch((err) => {
ElMessage.error(err.message);
done();
});
}
}
});
}
//
function onContextMenu(e: any, item: any) {
ContextMenu.open(e, {
hover: {
target: "item"
},
list: [
{
label: "编辑",
hidden: !getPerm(service.dict.type, ["update"]),
callback(done) {
done();
edit(item);
}
},
{
label: "删除",
hidden: !getPerm(service.dict.type, ["delete"]),
callback(done) {
done();
ElMessageBox.confirm("是否要删除该类型?", "提示", {
type: "warning"
})
.then(() => {
service.dict.type
.delete({
ids: [item.id]
})
.then(async () => {
ElMessage.success("删除成功");
//
await refresh();
//
if (active.value == item.id) {
select(list.value[0]);
}
})
.catch((err) => {
ElMessage.error(err.message);
});
})
.catch(() => null);
}
}
]
});
}
onMounted(() => {
refresh();
});
</script>
<style lang="scss" scoped>
.dict-group {
height: 100%;
width: 100%;
box-sizing: border-box;
.head {
display: flex;
align-items: center;
justify-content: space-between;
height: 40px;
font-size: 14px;
padding: 0 10px;
white-space: nowrap;
}
ul {
max-height: calc(100% - 40px);
padding: 10px;
box-sizing: border-box;
overflow: hidden auto;
li {
display: flex;
align-items: center;
width: 100%;
list-style: none;
box-sizing: border-box;
padding: 10px 35px 10px 10px;
cursor: pointer;
font-size: 14px;
margin-bottom: 10px;
border-radius: 3px;
color: #666;
background-color: #f7f7f7;
.el-icon {
position: absolute;
right: 20px;
}
&:last-child {
margin-bottom: 0;
}
&.is-active {
background-color: var(--color-primary);
color: #fff;
}
&:hover {
opacity: 0.8;
}
}
}
}
</style>

View File

@ -0,0 +1,7 @@
import { useStore } from "./store";
export function useDict() {
return {
...useStore()
};
}

View File

@ -0,0 +1,52 @@
import { sortBy } from "lodash";
import { defineStore } from "pinia";
import { computed, reactive } from "vue";
import { isDev, useCool } from "/@/cool";
declare interface Data {
[key: string]: Array<{ label: string; value: any }>;
}
export const useDictStore = defineStore("dict", () => {
const { service } = useCool();
// 对象数据
const data = reactive<Data>({});
// 获取
function get(name: string) {
return computed(() => data[name]);
}
// 刷新
function refresh(types?: string[]) {
service.dict.info
.data({
types
})
.then((res) => {
const d: any = {};
for (const i in res) {
d[i] = sortBy(res[i], "orderNum").map((e) => {
return {
label: e.name,
value: e.id
};
});
}
Object.assign(data, d);
if (isDev) {
console.log("字典数据", data);
}
});
}
return {
data,
get,
refresh
};
});

View File

@ -0,0 +1,9 @@
import { useDictStore } from "./dict";
export function useStore() {
const dict = useDictStore();
return {
dict
};
}

View File

@ -0,0 +1,120 @@
<template>
<cl-view-group :title="title">
<template #left>
<Group />
</template>
<template #right>
<cl-crud ref="Crud">
<el-row>
<!-- 刷新按钮 -->
<cl-refresh-btn />
<!-- 新增按钮 -->
<cl-add-btn :disabled="!group" />
<!-- 删除按钮 -->
<cl-multi-delete-btn />
<cl-flex1 />
<!-- 关键字搜索 -->
<cl-search-key />
</el-row>
<el-row>
<!-- 数据表格 -->
<cl-table
ref="Table"
:default-sort="{
prop: 'orderNum',
order: 'descending'
}"
/>
</el-row>
<el-row>
<cl-flex1 />
<!-- 分页控件 -->
<cl-pagination />
</el-row>
<!-- 新增编辑 -->
<cl-upsert ref="Upsert" />
</cl-crud>
</template>
</cl-view-group>
</template>
<script lang="ts" setup>
import { useCrud, useTable, useUpsert } from "@cool-vue/crud";
import { useCool } from "/@/cool";
import Group from "../components/group.vue";
import { computed, provide, ref } from "vue";
const { service, named } = useCool();
named("dict-list");
//
const group = ref();
//
const title = computed(() => {
return group.value ? `字典列表(${group.value.name}` : "字典列表";
});
// cl-upsert
const Upsert = useUpsert({
items: [
{ label: "名称", prop: "name", required: true, component: { name: "el-input" } },
{
label: "排序",
prop: "orderNum",
value: 1,
component: { name: "el-input-number", props: { min: 1 } }
},
{
label: "备注",
prop: "remark",
component: { name: "el-input", props: { type: "textarea", rows: 4 } }
}
],
onSubmit(_, data, { next }) {
next({
...data,
typeId: group.value.id
});
}
});
// cl-table
const Table = useTable({
columns: [
{ type: "selection" },
{ label: "名称", prop: "name" },
{ label: "排序", prop: "orderNum", sortable: "custom" },
{ label: "备注", prop: "remark", showOverflowTooltip: true },
{ label: "创建时间", prop: "createTime", sortable: "custom" },
{ label: "更新时间", prop: "updateTime", sortable: "custom" },
{ type: "op", buttons: ["edit", "delete"] }
]
});
// cl-crud
const Crud = useCrud({
service: service.dict.info
});
//
function refresh(params?: any) {
Crud.value?.refresh(params);
}
//
function setGroup(data: any) {
group.value = data;
}
provide("dict", {
group,
refresh,
setGroup
});
</script>

View File

@ -984,10 +984,10 @@
"@babel/helper-validator-identifier" "^7.16.7" "@babel/helper-validator-identifier" "^7.16.7"
to-fast-properties "^2.0.0" to-fast-properties "^2.0.0"
"@cool-vue/crud@^5.2.7": "@cool-vue/crud@^5.2.10":
version "5.2.7" version "5.2.10"
resolved "https://registry.npmjs.org/@cool-vue/crud/-/crud-5.2.7.tgz#4b3b693887dc077e839b531b7c7b8b2b94ee8c89" resolved "https://registry.npmjs.org/@cool-vue/crud/-/crud-5.2.10.tgz#e5aed2c7520372dba497787e5e6528ef48a2ace2"
integrity sha512-1HkYUs45vTxtZ3pYmlshnQF0YH6xYAL0txaPGN0QclIZ1DHtoyQBLfouZ+mJSOMfUnj8+RuOKlieDJRDhOK7Yg== integrity sha512-bsQSglIW9D1R/5qSDAnDNTKhp5tYQQJX7t0onD7ZIEifDyErSx3NJUChPiTZlS3N+B7/Az4676rPXzv3W3oWvw==
dependencies: dependencies:
array.prototype.flat "^1.2.4" array.prototype.flat "^1.2.4"
core-js "^3.21.1" core-js "^3.21.1"