🔱: [client] sync upgrade with 21 commits [trident-sync]

Update README.md
This commit is contained in:
xiaojunnuo
2023-01-29 15:26:45 +08:00
parent 62e3945d30
commit d10e80bf83
567 changed files with 36438 additions and 2 deletions
+280
View File
@@ -0,0 +1,280 @@
import _ from "lodash-es";
function copyList(originList, newList, options, parentId) {
for (const item of originList) {
const newItem = { ...item, parentId };
newItem.id = ++options.idGenerator;
newList.push(newItem);
if (item.children != null) {
newItem.children = [];
copyList(item.children, newItem.children, options, newItem.id);
}
}
}
function delById(req, list) {
for (let i = 0; i < list.length; i++) {
const item = list[i];
console.log("remove i", i, req, req.params.id, item.id);
if (item.id === parseInt(req.params.id)) {
console.log("remove i", i);
list.splice(i, 1);
break;
}
if (item.children != null && item.children.length > 0) {
delById(req, item.children);
}
}
}
function findById(id, list) {
for (const item of list) {
if (item.id === id) {
return item;
}
if (item.children != null && item.children.length > 0) {
const sub = findById(id, item.children);
if (sub != null) {
return sub;
}
}
}
}
export default {
findById,
buildMock(options) {
const name = options.name;
if (options.copyTimes == null) {
options.copyTimes = 29;
}
const list = [];
for (let i = 0; i < options.copyTimes; i++) {
copyList(options.list, list, options);
}
options.list = list;
return [
{
path: "/mock/" + name + "/page",
method: "get",
handle(req) {
let data = [...list];
let limit = 20;
let offset = 0;
for (const item of list) {
if (item.children != null && item.children.length === 0) {
item.hasChildren = false;
item.lazy = false;
}
}
let orderProp, orderAsc;
if (req && req.body) {
const { page, query, sort } = req.body;
if (page.limit != null) {
limit = parseInt(page.limit);
}
if (page.offset != null) {
offset = parseInt(page.offset);
}
orderProp = sort.prop;
orderAsc = sort.asc;
if (Object.keys(query).length > 0) {
data = list.filter((item) => {
let allFound = true; // 是否所有条件都符合
for (const key in query) {
// 判定某一个条件
const value = query[key];
if (value == null || value === "") {
continue;
}
if (value instanceof Array) {
// 如果条件中的value是数组的话,只要查到一个就行
if (value.length === 0) {
continue;
}
let found = false;
for (const i of value) {
if (item[key] instanceof Array) {
for (const j of item[key]) {
if (i === j) {
found = true;
break;
}
}
if (found) {
break;
}
} else if (item[key] === i || (typeof item[key] === "string" && item[key].indexOf(i + "") >= 0)) {
found = true;
break;
}
if (found) {
break;
}
}
if (!found) {
allFound = false;
}
} else if (value instanceof Object) {
for (const key2 in value) {
const v = value[key2];
if (v && item[key] && v !== item[key][key2]) {
return false;
}
}
} else if (item[key] !== value) {
allFound = false;
}
}
return allFound;
});
}
}
const start = offset;
let end = offset + limit;
if (data.length < end) {
end = data.length;
}
if (orderProp) {
// 排序
data.sort((a, b) => {
let ret = 0;
if (a[orderProp] > b[orderProp]) {
ret = 1;
} else {
ret = -1;
}
return orderAsc ? ret : -ret;
});
}
const records = data.slice(start, end);
const lastOffset = data.length - (data.length % limit);
if (offset > lastOffset) {
offset = lastOffset;
}
return {
code: 0,
msg: "success",
data: {
records: records,
total: data.length,
limit,
offset
}
};
}
},
{
path: "/mock/" + name + "/get",
method: "get",
handle(req) {
let id = req.params.id;
id = parseInt(id);
let current = null;
for (const item of list) {
if (item.id === id) {
current = item;
break;
}
}
return {
code: 0,
msg: "success",
data: current
};
}
},
{
path: "/mock/" + name + "/add",
method: "post",
handle(req) {
req.body.id = ++options.idGenerator;
list.unshift(req.body);
return {
code: 0,
msg: "success",
data: req.body.id
};
}
},
{
path: "/mock/" + name + "/update",
method: "post",
handle(req) {
const item = findById(req.body.id, list);
if (item) {
_.mergeWith(item, req.body, (objValue, srcValue) => {
if (srcValue == null) {
return;
}
// 如果被合并对象为数组,则直接被覆盖对象覆盖,只要覆盖对象不为空
if (_.isArray(objValue)) {
return srcValue;
}
});
}
return {
code: 0,
msg: "success",
data: null
};
}
},
{
path: "/mock/" + name + "/delete",
method: "post",
handle(req) {
delById(req, list);
return {
code: 0,
msg: "success",
data: null
};
}
},
{
path: "/mock/" + name + "/batchDelete",
method: "post",
handle(req) {
const ids = req.body.ids;
for (let i = list.length - 1; i >= 0; i--) {
const item = list[i];
if (ids.indexOf(item.id) >= 0) {
list.splice(i, 1);
}
}
return {
code: 0,
msg: "success",
data: null
};
}
},
{
path: "/mock/" + name + "/delete",
method: "post",
handle(req) {
delById(req, list);
return {
code: 0,
msg: "success",
data: null
};
}
},
{
path: "/mock/" + name + "/all",
method: "post",
handle(req) {
return {
code: 0,
msg: "success",
data: list
};
}
}
];
}
};
@@ -0,0 +1,268 @@
export default [
{
value: "zhinan",
label: "指南",
children: [
{
value: "shejiyuanze",
label: "设计原则",
children: [
{
value: "yizhi",
label: "一致"
},
{
value: "fankui",
label: "反馈"
},
{
value: "xiaolv",
label: "效率"
},
{
value: "kekong",
label: "可控"
}
]
},
{
value: "daohang",
label: "导航",
children: [
{
value: "cexiangdaohang",
label: "侧向导航"
},
{
value: "dingbudaohang",
label: "顶部导航"
}
]
}
]
},
{
value: "zujian",
label: "组件",
children: [
{
value: "basic",
label: "Basic",
children: [
{
value: "layout",
label: "Layout 布局"
},
{
value: "color",
label: "Color 色彩"
},
{
value: "typography",
label: "Typography 字体"
},
{
value: "icon",
label: "Icon 图标"
},
{
value: "button",
label: "Button 按钮"
}
]
},
{
value: "form",
label: "Form",
children: [
{
value: "radio",
label: "Radio 单选框"
},
{
value: "checkbox",
label: "Checkbox 多选框"
},
{
value: "input",
label: "Input 输入框"
},
{
value: "input-number",
label: "InputNumber 计数器"
},
{
value: "select",
label: "Select 选择器"
},
{
value: "cascader",
label: "Cascader 级联选择器"
},
{
value: "switch",
label: "Switch 开关"
},
{
value: "slider",
label: "Slider 滑块"
},
{
value: "time-picker",
label: "TimePicker 时间选择器"
},
{
value: "date-picker",
label: "DatePicker 日期选择器"
},
{
value: "datetime-picker",
label: "DateTimePicker 日期时间选择器"
},
{
value: "upload",
label: "Upload 上传"
},
{
value: "rate",
label: "Rate 评分"
},
{
value: "form1",
label: "Form 表单"
}
]
},
{
value: "data",
label: "Data",
children: [
{
value: "table",
label: "Table 表格"
},
{
value: "tag",
label: "Tag 标签"
},
{
value: "progress",
label: "Progress 进度条"
},
{
value: "tree",
label: "Tree 树形控件"
},
{
value: "pagination",
label: "Pagination 分页"
},
{
value: "badge",
label: "Badge 标记"
}
]
},
{
value: "notice",
label: "Notice",
children: [
{
value: "alert",
label: "Alert 警告"
},
{
value: "loading",
label: "Loading 加载"
},
{
value: "message",
label: "Message 消息提示"
},
{
value: "message-box",
label: "MessageBox 弹框"
},
{
value: "notification",
label: "Notification 通知"
}
]
},
{
value: "navigation",
label: "Navigation",
children: [
{
value: "menu",
label: "NavMenu 导航菜单"
},
{
value: "tabs",
label: "Tabs 标签页"
},
{
value: "breadcrumb",
label: "Breadcrumb 面包屑"
},
{
value: "dropdown",
label: "Dropdown 下拉菜单"
},
{
value: "steps",
label: "Steps 步骤条"
}
]
},
{
value: "others",
label: "Others",
children: [
{
value: "dialog",
label: "Dialog 对话框"
},
{
value: "tooltip",
label: "Tooltip 文字提示"
},
{
value: "popover",
label: "Popover 弹出框"
},
{
value: "card",
label: "Card 卡片"
},
{
value: "carousel",
label: "Carousel 走马灯"
},
{
value: "collapse",
label: "Collapse 折叠面板"
}
]
}
]
},
{
value: "ziyuan",
label: "资源",
children: [
{
value: "axure",
label: "Axure Components"
},
{
value: "sketch",
label: "Sketch Templates"
},
{
value: "jiaohu",
label: "组件交互文档"
}
]
}
];
@@ -0,0 +1,123 @@
import cascaderData from "./cascader-data";
import pcaDataLittle from "./pca-data-little";
import { TreeNodesLazyLoader, getPcaData } from "./pcas-data";
const openStatus = [
{ value: "1", label: "打开", color: "success",icon:"ion:radio-button-on" },
{ value: "2", label: "停止", color: "cyan" },
{ value: "0", label: "关闭", color: "red",icon:"ion:radio-button-off" }
];
const moreOpenStatus = [
{ value: "1", label: "打开(open)", color: "success" },
{ value: "2", label: "停止(stop)", color: "cyan" },
{ value: "0", label: "关闭(close)", color: "red" }
];
const textStatus = [
{ id: "1", text: "打开", color: "success" },
{ id: "2", text: "停止", color: "cyan" },
{ id: "0", text: "关闭", color: "red" }
];
export function GetTreeChildrenByParentId(parentId) {
return TreeNodesLazyLoader.getChildren(parentId);
}
export function GetNodesByValues(values) {
return TreeNodesLazyLoader.getNodesByValues(values);
}
export default [
{
path: "/mock/dicts/OpenStatusEnum",
method: "get",
handle() {
return {
code: 0,
msg: "success",
data: openStatus
};
}
},
{
path: "/mock/dicts/_OpenStatusEnum2",
method: "get",
handle() {
return {
code: 0,
msg: "success",
data: textStatus
};
}
},
{
path: "/mock/dicts/moreOpenStatusEnum",
method: "get",
handle() {
return {
code: 0,
msg: "success",
data: moreOpenStatus
};
}
},
{
path: "/mock/dicts/cascaderData",
method: "get",
handle() {
return {
code: 0,
msg: "success",
data: cascaderData
};
}
},
{
path: "/mock/dicts/pca",
method: "get",
async handle() {
const data = await getPcaData();
return {
code: 0,
msg: "success",
data: data
};
}
},
{
path: "/mock/dicts/littlePca",
method: "get",
async handle() {
return {
code: 0,
msg: "success",
data: pcaDataLittle
};
}
},
{
path: "/mock/tree/GetTreeChildrenByParentId",
method: "get",
async handle({ params }) {
const list = await GetTreeChildrenByParentId(params.parentId);
return {
code: 0,
msg: "success",
data: list
};
}
},
{
path: "/mock/tree/GetNodesByValues",
method: "get",
async handle({ params }) {
const list = await GetNodesByValues(params.values);
return {
code: 0,
msg: "success",
data: list
};
}
}
];
@@ -0,0 +1,70 @@
export default [
{
code: "1",
name: "北京",
children: [
{
code: "2",
name: "北京市区",
children: [
{
code: "3",
name: "海淀"
},
{
code: "4",
name: "朝阳"
}
]
},
{
code: "5",
name: "北京郊区",
children: [
{
code: "6",
name: "海淀郊区"
},
{
code: "7",
name: "朝阳郊区"
}
]
}
]
},
{
code: "11",
name: "深圳",
children: [
{
code: "12",
name: "深圳市区",
children: [
{
code: "13",
name: "南山"
},
{
code: "14",
name: "福田"
}
]
},
{
code: "15",
name: "深圳郊区",
children: [
{
code: "16",
name: "南山郊区"
},
{
code: "17",
name: "福田郊区"
}
]
}
]
}
];
@@ -0,0 +1,87 @@
import _ from "lodash-es";
export async function getPcasData() {
const pcasData = () => import("china-division/dist/pcas-code.json");
const ret = await pcasData();
return ret.default;
}
export async function getPcaData() {
const pcaData = () => import("china-division/dist/pca-code.json");
const ret = await pcaData();
return ret.default;
}
export const TreeNodesLazyLoader = {
getNodesByValues(values) {
console.log("getNodesByValues", values);
if (!(values instanceof Array)) {
values = [values];
}
return getPcasData().then((data) => {
const nodes = [];
for (const value of values) {
const found = this.getNode(data, value);
if (found) {
const target = _.cloneDeep(found);
delete target.children;
nodes.push(target);
}
}
return nodes;
});
},
getNode(list, value) {
for (const item of list) {
if (item.code === value) {
return item;
}
if (item.children && item.children.length > 0) {
const found = this.getNode(item.children, value);
if (found) {
return found;
}
}
}
},
getChildren(parent) {
return getPcasData().then((data) => {
const list = this.getChildrenByParent(parent, data);
if (list == null) {
return [];
}
return this.cloneAndDeleteChildren(list);
});
},
getChildrenByParent(parentId, tree) {
if (!parentId) {
// 取第一级
return tree;
} else {
for (const node of tree) {
if (node.code === parentId) {
return node.children;
}
if (node.children && node.children.length > 0) {
// 递归查找
const list = this.getChildrenByParent(parentId, node.children);
if (list) {
return list;
}
}
}
}
},
cloneAndDeleteChildren(list) {
const newList = [];
for (const node of list) {
const newNode = {};
Object.assign(newNode, node);
if (newNode.children == null || newNode.children.length === 0) {
newNode.isLeaf = true;
newNode.leaf = true;
}
delete newNode.children;
newList.push(newNode);
}
console.log("found children:", newList);
return newList;
}
};
@@ -0,0 +1,49 @@
import { mock } from "../api/service";
import * as tools from "../api/tools";
import _ from "lodash-es";
const commonMocks = import.meta.globEager("./common/mock.*.js");
const apiMocks = import.meta.globEager("../api/modules/*.mock.ts");
const viewMocks = import.meta.globEager("../views/**/mock.js");
const list = [];
_.forEach(commonMocks, (value) => {
list.push(value.default);
});
_.forEach(apiMocks, (value) => {
list.push(value.default);
});
_.forEach(viewMocks, (value) => {
list.push(value.default);
});
list.forEach((apiFile) => {
for (const item of apiFile) {
mock.onAny(new RegExp(item.path)).reply(async (config) => {
console.log("------------fake request start -------------");
console.log("request:", config);
const data = config.data ? JSON.parse(config.data) : {};
const query = config.url.indexOf("?") >= 0 ? config.url.substring(config.url.indexOf("?") + 1) : undefined;
const params = config.params || {};
if (query) {
const arr = query.split("&");
for (const item of arr) {
const kv = item.split("=");
params[kv[0]] = kv[1];
}
}
const req = {
body: data,
params: params
};
const ret = await item.handle(req);
console.log("response:", ret);
console.log("------------fake request end-------------");
if (ret.code === 0) {
return tools.responseSuccess(ret.data, ret.msg);
} else {
return tools.responseError(ret.data, ret.msg, ret.code);
}
});
}
});