mirror of
https://github.com/certd/certd.git
synced 2026-05-15 20:47:31 +08:00
🔱: [client] sync upgrade with 12 commits [trident-sync]
refactor: 1.11.0 refactor: 1.11.0 refactor: 1.11.0 refactor: 1.11.0 refactor: ts化 refactor: ts化 feat: 全面TS化 perf: 全面ts化 refactor: 继续优化ts perf: ts定义优化 fix: 修复wangeditor无法上传视频的bug
This commit is contained in:
+19
-17
@@ -1,5 +1,5 @@
|
||||
import _ from "lodash-es";
|
||||
function copyList(originList, newList, options, parentId) {
|
||||
function copyList(originList: any, newList: any, options: any, parentId?: any) {
|
||||
for (const item of originList) {
|
||||
const newItem = { ...item, parentId };
|
||||
newItem.id = ++options.idGenerator;
|
||||
@@ -11,7 +11,7 @@ function copyList(originList, newList, options, parentId) {
|
||||
}
|
||||
}
|
||||
|
||||
function delById(req, list) {
|
||||
function delById(req: any, list: any) {
|
||||
for (let i = 0; i < list.length; i++) {
|
||||
const item = list[i];
|
||||
console.log("remove i", i, req, req.params.id, item.id);
|
||||
@@ -26,27 +26,27 @@ function delById(req, list) {
|
||||
}
|
||||
}
|
||||
|
||||
function findById(id, list) {
|
||||
function findById(id: any, list: any) {
|
||||
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);
|
||||
const sub: any = findById(id, item.children);
|
||||
if (sub != null) {
|
||||
return sub;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
export default {
|
||||
const mockUtil: any = {
|
||||
findById,
|
||||
buildMock(options) {
|
||||
buildMock(options: any) {
|
||||
const name = options.name;
|
||||
if (options.copyTimes == null) {
|
||||
options.copyTimes = 29;
|
||||
}
|
||||
const list = [];
|
||||
const list: any = [];
|
||||
for (let i = 0; i < options.copyTimes; i++) {
|
||||
copyList(options.list, list, options);
|
||||
}
|
||||
@@ -55,7 +55,7 @@ export default {
|
||||
{
|
||||
path: "/mock/" + name + "/page",
|
||||
method: "get",
|
||||
handle(req) {
|
||||
handle(req: any) {
|
||||
let data = [...list];
|
||||
let limit = 20;
|
||||
let offset = 0;
|
||||
@@ -65,7 +65,7 @@ export default {
|
||||
item.lazy = false;
|
||||
}
|
||||
}
|
||||
let orderProp, orderAsc;
|
||||
let orderProp: any, orderAsc: any;
|
||||
if (req && req.body) {
|
||||
const { page, query, sort } = req.body;
|
||||
if (page.limit != null) {
|
||||
@@ -78,7 +78,7 @@ export default {
|
||||
orderAsc = sort.asc;
|
||||
|
||||
if (Object.keys(query).length > 0) {
|
||||
data = list.filter((item) => {
|
||||
data = list.filter((item: any) => {
|
||||
let allFound = true; // 是否所有条件都符合
|
||||
for (const key in query) {
|
||||
// 判定某一个条件
|
||||
@@ -169,7 +169,7 @@ export default {
|
||||
{
|
||||
path: "/mock/" + name + "/get",
|
||||
method: "get",
|
||||
handle(req) {
|
||||
handle(req: any) {
|
||||
let id = req.params.id;
|
||||
id = parseInt(id);
|
||||
let current = null;
|
||||
@@ -189,7 +189,7 @@ export default {
|
||||
{
|
||||
path: "/mock/" + name + "/add",
|
||||
method: "post",
|
||||
handle(req) {
|
||||
handle(req: any) {
|
||||
req.body.id = ++options.idGenerator;
|
||||
list.unshift(req.body);
|
||||
return {
|
||||
@@ -202,7 +202,7 @@ export default {
|
||||
{
|
||||
path: "/mock/" + name + "/update",
|
||||
method: "post",
|
||||
handle(req) {
|
||||
handle(req: any): any {
|
||||
const item = findById(req.body.id, list);
|
||||
if (item) {
|
||||
_.mergeWith(item, req.body, (objValue, srcValue) => {
|
||||
@@ -225,7 +225,7 @@ export default {
|
||||
{
|
||||
path: "/mock/" + name + "/delete",
|
||||
method: "post",
|
||||
handle(req) {
|
||||
handle(req: any): any {
|
||||
delById(req, list);
|
||||
return {
|
||||
code: 0,
|
||||
@@ -237,7 +237,7 @@ export default {
|
||||
{
|
||||
path: "/mock/" + name + "/batchDelete",
|
||||
method: "post",
|
||||
handle(req) {
|
||||
handle(req: any): any {
|
||||
const ids = req.body.ids;
|
||||
for (let i = list.length - 1; i >= 0; i--) {
|
||||
const item = list[i];
|
||||
@@ -255,7 +255,7 @@ export default {
|
||||
{
|
||||
path: "/mock/" + name + "/delete",
|
||||
method: "post",
|
||||
handle(req) {
|
||||
handle(req: any): any {
|
||||
delById(req, list);
|
||||
return {
|
||||
code: 0,
|
||||
@@ -267,7 +267,7 @@ export default {
|
||||
{
|
||||
path: "/mock/" + name + "/all",
|
||||
method: "post",
|
||||
handle(req) {
|
||||
handle(req: any): any {
|
||||
return {
|
||||
code: 0,
|
||||
msg: "success",
|
||||
@@ -278,3 +278,5 @@ export default {
|
||||
];
|
||||
}
|
||||
};
|
||||
|
||||
export default mockUtil;
|
||||
+8
-6
@@ -1,11 +1,13 @@
|
||||
import cascaderData from "./cascader-data";
|
||||
// @ts-ignore
|
||||
import pcaDataLittle from "./pca-data-little";
|
||||
// @ts-ignore
|
||||
import { TreeNodesLazyLoader, getPcaData } from "./pcas-data";
|
||||
|
||||
const openStatus = [
|
||||
{ value: "1", label: "打开", color: "success",icon:"ion:radio-button-on" },
|
||||
{ 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" }
|
||||
{ value: "0", label: "关闭", color: "red", icon: "ion:radio-button-off" }
|
||||
];
|
||||
|
||||
const moreOpenStatus = [
|
||||
@@ -20,11 +22,11 @@ const textStatus = [
|
||||
{ id: "0", text: "关闭", color: "red" }
|
||||
];
|
||||
|
||||
export function GetTreeChildrenByParentId(parentId) {
|
||||
export function GetTreeChildrenByParentId(parentId: any) {
|
||||
return TreeNodesLazyLoader.getChildren(parentId);
|
||||
}
|
||||
|
||||
export function GetNodesByValues(values) {
|
||||
export function GetNodesByValues(values: any) {
|
||||
return TreeNodesLazyLoader.getNodesByValues(values);
|
||||
}
|
||||
|
||||
@@ -99,7 +101,7 @@ export default [
|
||||
{
|
||||
path: "/mock/tree/GetTreeChildrenByParentId",
|
||||
method: "get",
|
||||
async handle({ params }) {
|
||||
async handle({ params }: any) {
|
||||
const list = await GetTreeChildrenByParentId(params.parentId);
|
||||
return {
|
||||
code: 0,
|
||||
@@ -111,7 +113,7 @@ export default [
|
||||
{
|
||||
path: "/mock/tree/GetNodesByValues",
|
||||
method: "get",
|
||||
async handle({ params }) {
|
||||
async handle({ params }: any) {
|
||||
const list = await GetNodesByValues(params.values);
|
||||
return {
|
||||
code: 0,
|
||||
+10
-8
@@ -1,16 +1,18 @@
|
||||
import _ from "lodash-es";
|
||||
export async function getPcasData() {
|
||||
// @ts-ignore
|
||||
const pcasData = () => import("china-division/dist/pcas-code.json");
|
||||
const ret = await pcasData();
|
||||
return ret.default;
|
||||
}
|
||||
export async function getPcaData() {
|
||||
// @ts-ignore
|
||||
const pcaData = () => import("china-division/dist/pca-code.json");
|
||||
const ret = await pcaData();
|
||||
return ret.default;
|
||||
}
|
||||
export const TreeNodesLazyLoader = {
|
||||
getNodesByValues(values) {
|
||||
getNodesByValues(values: any) {
|
||||
console.log("getNodesByValues", values);
|
||||
if (!(values instanceof Array)) {
|
||||
values = [values];
|
||||
@@ -28,20 +30,20 @@ export const TreeNodesLazyLoader = {
|
||||
return nodes;
|
||||
});
|
||||
},
|
||||
getNode(list, value) {
|
||||
getNode(list: any, value: any) {
|
||||
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);
|
||||
const found: any = this.getNode(item.children, value);
|
||||
if (found) {
|
||||
return found;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
getChildren(parent) {
|
||||
getChildren(parent: any) {
|
||||
return getPcasData().then((data) => {
|
||||
const list = this.getChildrenByParent(parent, data);
|
||||
if (list == null) {
|
||||
@@ -50,7 +52,7 @@ export const TreeNodesLazyLoader = {
|
||||
return this.cloneAndDeleteChildren(list);
|
||||
});
|
||||
},
|
||||
getChildrenByParent(parentId, tree) {
|
||||
getChildrenByParent(parentId: any, tree: any) {
|
||||
if (!parentId) {
|
||||
// 取第一级
|
||||
return tree;
|
||||
@@ -61,7 +63,7 @@ export const TreeNodesLazyLoader = {
|
||||
}
|
||||
if (node.children && node.children.length > 0) {
|
||||
// 递归查找
|
||||
const list = this.getChildrenByParent(parentId, node.children);
|
||||
const list: any = this.getChildrenByParent(parentId, node.children);
|
||||
if (list) {
|
||||
return list;
|
||||
}
|
||||
@@ -69,10 +71,10 @@ export const TreeNodesLazyLoader = {
|
||||
}
|
||||
}
|
||||
},
|
||||
cloneAndDeleteChildren(list) {
|
||||
cloneAndDeleteChildren(list: any) {
|
||||
const newList = [];
|
||||
for (const node of list) {
|
||||
const newNode = {};
|
||||
const newNode: any = {};
|
||||
Object.assign(newNode, node);
|
||||
if (newNode.children == null || newNode.children.length === 0) {
|
||||
newNode.isLeaf = true;
|
||||
+9
-6
@@ -1,12 +1,15 @@
|
||||
import { mock } from "../api/service";
|
||||
import * as tools from "../api/tools";
|
||||
import _ from "lodash-es";
|
||||
const commonMocks = import.meta.glob("./common/mock.*.[j|t]s", { eager: true });
|
||||
const apiMocks = import.meta.glob("../api/modules/*.mock.ts", { eager: true });
|
||||
const viewMocks = import.meta.glob("../views/**/mock.[j|t]s", { eager: true });
|
||||
// @ts-ignore
|
||||
const commonMocks: any = import.meta.glob("./common/mock.*.[j|t]s", { eager: true });
|
||||
// @ts-ignore
|
||||
const apiMocks: any = import.meta.glob("../api/modules/*.mock.ts", { eager: true });
|
||||
// @ts-ignore
|
||||
const viewMocks: any = import.meta.glob("../views/**/mock.[j|t]s", { eager: true });
|
||||
|
||||
const list = [];
|
||||
_.forEach(commonMocks, (value) => {
|
||||
const list: any = [];
|
||||
_.forEach(commonMocks, (value: any) => {
|
||||
list.push(value.default);
|
||||
});
|
||||
_.forEach(apiMocks, (value) => {
|
||||
@@ -16,7 +19,7 @@ _.forEach(viewMocks, (value) => {
|
||||
list.push(value.default);
|
||||
});
|
||||
|
||||
list.forEach((apiFile) => {
|
||||
list.forEach((apiFile: any) => {
|
||||
for (const item of apiFile) {
|
||||
mock.onAny(new RegExp(item.path)).reply(async (config) => {
|
||||
console.log("------------fake request start -------------");
|
||||
Reference in New Issue
Block a user