Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

测试 #3

Merged
merged 29 commits into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Node.js with Vue
# Build a Node.js project that uses Vue.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/javascript

trigger:
- master

pool:
vmImage: ubuntu-latest

steps:
- task: NodeTool@0
inputs:
versionSpec: '10.x'
displayName: 'Install Node.js'

- script: |
npm install -g pnpm
pnpm run build
displayName: 'npm install and build'
182 changes: 67 additions & 115 deletions mock/auth/menu.mock.ts
Original file line number Diff line number Diff line change
@@ -1,122 +1,74 @@
import { definePostMock } from "../config";
import Mock from 'mockjs'
export const menu = [
{
id: 1,
name: '控制台',
route_path: "/console",
parent_id: 0,
icon: "mingcute:confused-fill"
},
{
id: 2,
name: '工单管理',
route_path: "/console",
parent_id: 0,
icon: "mingcute:confused-fill"
},
{
id: 3,
name: '企业管理',
route_path: "/system/user",
parent_id: 0,
icon: "mingcute:confused-fill"
},
{
id: 4,
name: '角色管理',
route_path: "/system/role",
parent_id: 3,
icon: "mingcute:confused-fill"
},
{
id: 5,
name: '测试',
route_path: "/system/role",
parent_id: 3,
icon: "mingcute:confused-fill"
}
]
const findItem = <T extends object>(where: T) => {
return menu.find((item) => {
return Object.keys(where).every((key) => {
return item[key] === where[key]
})
})
}
const findList = <T extends object>(where: T) => {
return menu.filter((item) => {
return Object.keys(where).every((key) => {
return item[key] === where[key]
})
})
}
export const user = Mock.mock({
"total|1-1000": 1,
'list|10': [
{
'id|+1': 1,
name: "@cname",
created_at: "@datetime",
updated_at: "@datetime",
}
]
})
import { menu } from "../database/auth";
import Mock from "mockjs";
import { page, find, where } from "../utils";
export default definePostMock([
{
url: '/system/menu',
method: "GET",
delay: 1000,
body(request) {
const { page, limit } = request.query;
const start = (page - 1) * limit;
const end = start + parseInt(limit);;
return {
total: user.list.length,
list: user.list.slice(start, end)
}
}
{
url: "/system/menu",
method: "GET",
delay: 500,
body(request) {
const { page: start = 1, limit = 10 } = request.query;
const parent_id = request.query.parent_id || 0;
console.log(parent_id);
const result = where(menu.list, { parent_id });
const res = page(result, start, limit);
return {
total: menu.list.length,
list: res,
};
},
{
url: '/system/menu/:id',
method: "GET",
body(request) {
const id = request.params.id as number
if (id && user.list[id - 1]) return user.list[id - 1]
return {
error_code: 400,
msg: 'author not found',
}

}
},
{
url: "/system/menu/:id",
method: "GET",
body(request) {
const id = request.params.id as number;
const index = menu.list.findIndex((item) => item.id == id);
if (index) return menu.list[index];
return {
error_code: 400,
msg: "author not found",
};
},
{
url: '/system/menu',
method: "POST",
body(request) {
request.body.id = Mock.Random.integer();
user.list.push(request.body);
return request.body
}
},
{
url: "/system/menu",
method: "POST",
body(request) {
request.body.id = menu.list.length + 10;
request.body.created_at = Mock.Random.datetime();
request.body.updated_at = Mock.Random.datetime();
//@ts-ignore
menu.list.unshift(request.body);
return request.body;
},
{
url: '/system/menu/:id',
method: "PUT",
body(request) {
// user.list[]
const id = request.params.id as number
user.list[id - 1] = Object.assign(user.list[id - 1], request.body)
return user.list[id - 1]
}
},
{
url: "/system/menu/:id",
method: "PUT",
body(request) {
const id = request.params.id as number;
const index = menu.list.findIndex((item) => item.id == id);
Object.assign(menu.list[index], request.body);
return menu.list[index];
},
{
url: '/system/menu/:id',
method: "DELETE",
body(request) {
// user.list[]
const id = request.params.id as number
user.list.splice(id - 1, 1);
return user.list[id - 1];
}
},
{
url: "/system/menu/:id",
method: "DELETE",
body(request) {
const id = request.params.id as number;
const index = menu.list.findIndex((item) => item.id == id);
const deleteRueslt = menu.list.splice(index, 1);
if (deleteRueslt) {
return {
error_code: 400,
msg: "author not found",
};
}
const result = menu.list[index];
return result;
},
])
},
]);
128 changes: 63 additions & 65 deletions mock/auth/role.mock.ts
Original file line number Diff line number Diff line change
@@ -1,72 +1,70 @@
import { definePostMock } from "../config";
import Mock from 'mockjs'
import { page } from "../utils";
export const user = Mock.mock({
"total|100-1000": 1,
'list|100': [
{
'id|+1': 1,
"name": "@name",
"system_menu_ids": '@range(1, 10, 3)',
"desc": "@paragraph",
created_at: "@datetime",
updated_at: "@datetime",
}
]
})
import { role } from "../database/auth";
import Mock from "mockjs";
import { page, find } from "../utils";
export default definePostMock([
{
url: '/system/role',
method: "GET",
delay: 1000,
body(request) {
const { page: start, limit } = request.query;
return {
total: user.list.length,
list: page(user.list, start, limit)
}
}
{
url: "/system/role",
method: "GET",
delay: 500,
body(request) {
const { page: start = 1, limit = 10 } = request.query;
const result = page(role.list, start, limit);
return {
total: role.list.length,
list: result,
};
},
{
url: '/system/role/:id',
method: "GET",
body(request) {
const id = request.params.id as number
if (id && user.list[id - 1]) return user.list[id - 1]
return {
error_code: 400,
msg: 'author not found',
}

}
},
{
url: "/system/role/:id",
method: "GET",
body(request) {
const id = request.params.id as number;
const index = role.list.findIndex((item) => item.id == id);
if (index) return role.list[index];
return {
error_code: 400,
msg: "author not found",
};
},
{
url: '/system/role',
method: "POST",
body(request) {
request.body.id = Mock.Random.integer();
user.list.push(request.body);
return request.body
}
},
{
url: "/system/role",
method: "POST",
body(request) {
request.body.id = role.list.length + 10;
request.body.created_at = Mock.Random.datetime();
request.body.updated_at = Mock.Random.datetime();
role.list.unshift(request.body);
return request.body;
},
{
url: '/system/role/:id',
method: "PUT",
body(request) {
// user.list[]
const id = request.params.id as number
user.list[id - 1] = Object.assign(user.list[id - 1], request.body)
return user.list[id - 1]
}
},
{
url: "/system/role/:id",
method: "PUT",
body(request) {
const id = request.params.id as number;
const index = role.list.findIndex((item) => item.id == id);
Object.assign(role.list[index], request.body);
return role.list[index];
},
{
url: '/system/role/:id',
method: "DELETE",
body(request) {
// user.list[]
const id = request.params.id as number
user.list.splice(id - 1, 1);
return user.list[id - 1];
}
},
{
url: "/system/role/:id",
method: "DELETE",
body(request) {
const id = request.params.id as number;
const index = role.list.findIndex((item) => item.id == id);
const deleteRueslt = role.list.splice(index, 1);
if (deleteRueslt) {
return {
error_code: 400,
msg: "author not found",
};
}
const result = role.list[index];
return result;
},
])
},
]);
Loading