mirror of
https://github.com/cool-team-official/cool-admin-vue.git
synced 2025-12-14 23:12:51 +00:00
创建菜单的匹配规则添加 “组模式”
This commit is contained in:
parent
622a69a729
commit
b4886a77e4
@ -9,7 +9,7 @@
|
||||
"lint:eslint": "eslint \"{src}/**/*.{vue,ts,tsx}\" --fix"
|
||||
},
|
||||
"dependencies": {
|
||||
"@cool-vue/crud": "^6.1.10",
|
||||
"@cool-vue/crud": "^6.1.11",
|
||||
"@element-plus/icons-vue": "^2.0.10",
|
||||
"@vueuse/core": "^9.1.0",
|
||||
"@wangeditor/editor": "^5.1.23",
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import { Merge } from "/@/cool";
|
||||
|
||||
export const Colors = [
|
||||
"#409EFF",
|
||||
"#67C23A",
|
||||
@ -11,7 +13,52 @@ export const Colors = [
|
||||
"#FB78F2"
|
||||
];
|
||||
|
||||
export const PropRules = [
|
||||
export const PropRules: {
|
||||
test?: any[];
|
||||
group?: string[];
|
||||
table?: Merge<
|
||||
DeepPartial<ClTable.Column>,
|
||||
{
|
||||
name?: string;
|
||||
props?: {
|
||||
[key: string]: any;
|
||||
};
|
||||
}
|
||||
>;
|
||||
form?: ClForm.Item;
|
||||
handler?: string;
|
||||
order?: number;
|
||||
}[] = [
|
||||
{
|
||||
group: ["province", "city", "district"],
|
||||
table: {
|
||||
label: "省市区",
|
||||
formatter(row) {
|
||||
return row.province + "-" + row.city + "-" + row.district;
|
||||
}
|
||||
},
|
||||
form: {
|
||||
label: "省市区",
|
||||
prop: "pca",
|
||||
hook: "pca",
|
||||
component: {
|
||||
name: "cl-distpicker"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
test: ["address", "addr"],
|
||||
table: {
|
||||
showOverflowTooltip: true
|
||||
},
|
||||
form: {
|
||||
name: "el-input",
|
||||
props: {
|
||||
type: "textarea",
|
||||
rows: 3
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
test: ["createTime"],
|
||||
table: {
|
||||
@ -105,12 +152,10 @@ export const PropRules = [
|
||||
}
|
||||
},
|
||||
form: {
|
||||
component: {
|
||||
name: "el-date-picker",
|
||||
props: {
|
||||
type: "daterange",
|
||||
valueFormat: "YYYY-MM-DD"
|
||||
}
|
||||
name: "el-date-picker",
|
||||
props: {
|
||||
type: "daterange",
|
||||
valueFormat: "YYYY-MM-DD"
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -118,13 +163,11 @@ export const PropRules = [
|
||||
{
|
||||
test: ["times", "timeRange", "timeScope"],
|
||||
form: {
|
||||
component: {
|
||||
name: "el-date-picker",
|
||||
props: {
|
||||
type: "datetimerange",
|
||||
valueFormat: "YYYY-MM-DD HH:mm:ss",
|
||||
defaultTime: [new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 1, 1, 23, 59, 59)]
|
||||
}
|
||||
name: "el-date-picker",
|
||||
props: {
|
||||
type: "datetimerange",
|
||||
valueFormat: "YYYY-MM-DD HH:mm:ss",
|
||||
defaultTime: [new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 1, 1, 23, 59, 59)]
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -167,12 +210,14 @@ export const PropRules = [
|
||||
{
|
||||
test: ["num", "price", "age", "amount", "stock"],
|
||||
form: {
|
||||
name: "el-input-number",
|
||||
hook: {
|
||||
bind: ["number"]
|
||||
},
|
||||
props: {
|
||||
min: 0
|
||||
component: {
|
||||
name: "el-input-number",
|
||||
props: {
|
||||
min: 0
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@ -101,10 +101,7 @@ export function useChatGPT() {
|
||||
|
||||
// 发送
|
||||
function send(data: { name: string; columns: string[]; module: string }) {
|
||||
socket?.emit("data", {
|
||||
...data,
|
||||
apiKey: apiKey.value
|
||||
});
|
||||
socket?.emit("data", data);
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { ElMessage } from "element-plus";
|
||||
import { last } from "lodash-es";
|
||||
import { MenuData } from "../types";
|
||||
import { createComponent } from "../utils";
|
||||
import { createComponent, toCodeString } from "../utils";
|
||||
import { service } from "/@/cool";
|
||||
|
||||
export function useCode() {
|
||||
@ -20,7 +20,12 @@ export function useCode() {
|
||||
// 遍历
|
||||
columns.forEach((e) => {
|
||||
// 组件
|
||||
const { item, column } = createComponent(e);
|
||||
const { item, column, isHidden } = createComponent(e, columns);
|
||||
|
||||
// 过滤隐藏
|
||||
if (isHidden) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 验证规则
|
||||
if (!e.nullable) {
|
||||
@ -165,10 +170,10 @@ export function useCode() {
|
||||
const { service } = useCool();
|
||||
|
||||
// cl-upsert
|
||||
const Upsert = useUpsert(${JSON.stringify(upsert)});
|
||||
const Upsert = useUpsert(${toCodeString(upsert)});
|
||||
|
||||
// cl-table
|
||||
const Table = useTable(${JSON.stringify(table)});
|
||||
const Table = useTable(${toCodeString(table)});
|
||||
|
||||
// cl-crud
|
||||
const Crud = useCrud(
|
||||
|
||||
@ -80,32 +80,50 @@ const handler = {
|
||||
};
|
||||
|
||||
// 创建组件
|
||||
export function createComponent(entity: Entity) {
|
||||
export function createComponent(entity: Entity, columns: Entity[]) {
|
||||
const prop = entity.propertyName;
|
||||
let label = entity.comment;
|
||||
let d: any;
|
||||
let isHidden = false;
|
||||
|
||||
PropRules.find((r) => {
|
||||
const s = r.test.find((e) => {
|
||||
if (isRegExp(e)) {
|
||||
return e.test(prop);
|
||||
}
|
||||
let s = false;
|
||||
|
||||
if (isFunction(e)) {
|
||||
return e(prop);
|
||||
}
|
||||
|
||||
if (isString(e)) {
|
||||
if (e == prop) {
|
||||
return true;
|
||||
if (r.test) {
|
||||
s = !!r.test.find((e) => {
|
||||
if (isRegExp(e)) {
|
||||
return e.test(prop);
|
||||
}
|
||||
|
||||
const re = new RegExp(`${e}$`);
|
||||
return re.test(prop.toLocaleLowerCase());
|
||||
}
|
||||
if (isFunction(e)) {
|
||||
return e(prop);
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
if (isString(e)) {
|
||||
if (e == prop) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const re = new RegExp(`${e}$`);
|
||||
return re.test(prop.toLocaleLowerCase());
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
if (r.group) {
|
||||
if (
|
||||
r.group.includes(prop) &&
|
||||
r.group.some((e) => columns.find((c) => c.propertyName == e))
|
||||
) {
|
||||
if (r.group[0] == prop) {
|
||||
s = true;
|
||||
} else {
|
||||
isHidden = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (s) {
|
||||
if (r.handler) {
|
||||
@ -122,7 +140,7 @@ export function createComponent(entity: Entity) {
|
||||
}
|
||||
}
|
||||
|
||||
return !!s;
|
||||
return s;
|
||||
});
|
||||
|
||||
function parse(v: any) {
|
||||
@ -145,6 +163,28 @@ export function createComponent(entity: Entity) {
|
||||
|
||||
return {
|
||||
column: parse(d?.table),
|
||||
item: parse(d?.form)
|
||||
item: parse(d?.form),
|
||||
isHidden
|
||||
};
|
||||
}
|
||||
|
||||
// 转成代码字符串
|
||||
export function toCodeString(data: any) {
|
||||
const arr: string[][] = [];
|
||||
|
||||
let code = JSON.stringify(data, (key, value) => {
|
||||
if (isFunction(value)) {
|
||||
const str = value.toString();
|
||||
arr.push([JSON.stringify({ [key]: str }), str]);
|
||||
return str;
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
});
|
||||
|
||||
arr.forEach((e) => {
|
||||
code = code.replace(e[0].substring(1, e[0].length - 1), e[1]);
|
||||
});
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="label">Key</div>
|
||||
<!-- <div class="label">Key</div>
|
||||
|
||||
<div class="row">
|
||||
<el-input
|
||||
@ -58,7 +58,7 @@
|
||||
<Refresh />
|
||||
</el-icon>
|
||||
</el-button>
|
||||
</div>
|
||||
</div> -->
|
||||
|
||||
<div class="label">其他你想做的事?</div>
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user