Skip to content

Commit 774fca1

Browse files
committed
Merge branch 'hutu'
2 parents e7778ca + 5224853 commit 774fca1

File tree

17 files changed

+350
-25
lines changed

17 files changed

+350
-25
lines changed

package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,47 @@
22
"name": "my-vue-app",
33
"version": "0.0.0",
44
"scripts": {
5-
"dev": "vite --mode development",
5+
"dev": "vite --mode development",
66
"build": "vite build --mode production",
77
"preview": "vite preview"
88
},
99
"dependencies": {
1010
"axios": "^0.24.0",
1111
"echarts": "^5.2.2",
1212
"element-plus": "^1.2.0-beta.6",
13-
"element-resize-detector": "^1.2.4",
1413
"js-cookie": "^3.0.1",
1514
"nprogress": "^0.2.0",
1615
"screenfull": "^6.0.0",
16+
"sortablejs": "^1.14.0",
1717
"throttle-debounce": "^3.0.1",
1818
"vue": "^3.2.25",
1919
"vue-router": "^4.0.12",
2020
"vuex": "^4.0.2"
2121
},
2222
"devDependencies": {
23-
"@types/element-resize-detector": "^1.1.3",
2423
"@types/js-cookie": "^3.0.1",
24+
"@types/mockjs": "^1.0.5",
2525
"@types/node": "^16.11.13",
2626
"@types/nprogress": "^0.2.0",
27+
"@types/sortablejs": "^1.10.7",
2728
"@types/throttle-debounce": "^2.1.0",
2829
"@typescript-eslint/eslint-plugin": "^5.7.0",
2930
"@typescript-eslint/parser": "^5.7.0",
3031
"@vitejs/plugin-vue": "^2.0.0",
3132
"@vue/eslint-config-prettier": "^6.0.0",
3233
"@vue/eslint-config-typescript": "^9.1.0",
34+
"cross-env": "^7.0.3",
3335
"eslint": "^8.4.1",
3436
"eslint-plugin-prettier": "^4.0.0",
3537
"eslint-plugin-vue": "^8.2.0",
38+
"mockjs": "^1.1.0",
3639
"node-sass": "^7.0.0",
3740
"prettier": "^2.5.1",
3841
"sass": "^1.45.0",
3942
"sass-loader": "^12.4.0",
4043
"typescript": "^4.4.4",
4144
"vite": "^2.7.2",
45+
"vite-plugin-mock": "^2.9.6",
4246
"vue-tsc": "^0.29.8"
4347
}
4448
}

src/api/article.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { request } from '@/utils/http'
2+
//获取文章列表
3+
export const getArticleList = (params?: object): Promise<any> => {
4+
return request(`/api/article/list`, params, 'get')
5+
}

src/api/test.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/assets/iconfont/iconfont.scss

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
@font-face {
22
font-family: "iconfont"; /* Project id 3001982 */
3-
src: url('//at.alicdn.com/t/font_3001982_h7w46xo0a5b.woff2?t=1640829544328') format('woff2'),
4-
url('//at.alicdn.com/t/font_3001982_h7w46xo0a5b.woff?t=1640829544328') format('woff'),
5-
url('//at.alicdn.com/t/font_3001982_h7w46xo0a5b.ttf?t=1640829544328') format('truetype');
3+
src: url('//at.alicdn.com/t/font_3001982_uhnuq53veud.woff2?t=1642063257007') format('woff2'),
4+
url('//at.alicdn.com/t/font_3001982_uhnuq53veud.woff?t=1642063257007') format('woff'),
5+
url('//at.alicdn.com/t/font_3001982_uhnuq53veud.ttf?t=1642063257007') format('truetype');
66
}
77

88
.iconfont {
@@ -13,6 +13,22 @@
1313
-moz-osx-font-smoothing: grayscale;
1414
}
1515

16+
.icon-drag:before {
17+
content: "\e842";
18+
}
19+
20+
.icon-folder:before {
21+
content: "\e7d1";
22+
}
23+
24+
.icon-table:before {
25+
content: "\e7de";
26+
}
27+
28+
.icon-align-left:before {
29+
content: "\e7f5";
30+
}
31+
1632
.icon-caret-up:before {
1733
content: "\e8ed";
1834
}

src/components/EchartInit/Index.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @Author: hutu
44
* @Date: 2021-12-30 10:32:19
55
* @LastEditors: hutu
6-
* @LastEditTime: 2022-01-11 08:50:29
6+
* @LastEditTime: 2022-01-11 09:39:24
77
-->
88
<template>
99
<div :id="prop.id" :style="{ width: prop.width, height: prop.height }"></div>
@@ -84,6 +84,9 @@ const mounted = () => {
8484
const beforeDestroy = () => {
8585
destroyResizeEvent()
8686
destroySidebarResizeEvent()
87+
if (chart.value) {
88+
chart.value.dispose()
89+
}
8790
}
8891
8992
let firstFlag = false //首次渲染

src/interface/index.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,37 @@ export interface IThemeStyles {
5050
subMenuBg: string //子菜单栏背景颜色
5151
subMenuHover: string //子菜单栏悬浮颜色
5252
}
53+
export interface IPromise {
54+
code: number
55+
data: {
56+
items?: []
57+
total: number
58+
}
59+
message: string
60+
}
61+
/**
62+
* 文章列表
63+
*/
64+
export interface IArticleList {
65+
id: number
66+
title: string
67+
author: string
68+
type: string
69+
status: string
70+
pageviews: number
71+
created_at: string
72+
}
73+
/**
74+
* 文章列表查询
75+
*/
76+
export interface IArticleListQuery {
77+
type: string
78+
title: string
79+
page?: number
80+
limit?: number
81+
sort: string
82+
}
83+
5384
/**
5485
* 引入echarts
5586
*/
@@ -61,3 +92,8 @@ import { BarSeriesOption, LineSeriesOption, PieSeriesOption } from 'echarts/char
6192
import { TitleComponentOption, TooltipComponentOption, GridComponentOption } from 'echarts/components'
6293
// 通过 ComposeOption 来组合出一个只有必须组件和图表的 Option 类型
6394
export type IEchartsOption = echarts.ComposeOption<BarSeriesOption | LineSeriesOption | PieSeriesOption | TitleComponentOption | TooltipComponentOption | GridComponentOption>
95+
96+
/**
97+
* 字典
98+
*/
99+
export type IDictionary<T> = { [key: string]: T }

src/main.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import '@/styles/index.scss' //全局样式
66
import '@/assets/iconfont/iconfont.scss'
77
const app = createApp(App)
88

9-
import { ElButton, ElMenu, ElIcon, ElBreadcrumb, ElBreadcrumbItem, ElInput, ElForm, ElFormItem, ElTooltip, ElDropdown, ElDropdownItem, ElDropdownMenu, ElRow, ElCol, ElScrollbar } from 'element-plus'
9+
import { ElTag, ElButton, ElMenu, ElIcon, ElBreadcrumb, ElBreadcrumbItem, ElInput, ElForm, ElFormItem, ElTooltip, ElDropdown, ElDropdownItem, ElDropdownMenu, ElRow, ElCol, ElScrollbar, ElTable, ElTableColumn } from 'element-plus'
1010
import 'element-plus/theme-chalk/index.css'
1111
app.use(ElButton)
1212
app.use(ElMenu)
@@ -23,9 +23,12 @@ app.use(ElDropdownItem)
2323
app.use(ElRow)
2424
app.use(ElCol)
2525
app.use(ElScrollbar)
26-
26+
app.use(ElTable)
27+
app.use(ElTableColumn)
28+
app.use(ElTag)
2729
import './permission'
2830

31+
import './mock/index'
2932
app.use(router)
3033
app.use(store)
3134
app.mount('#app')

src/mock/article.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* @Description:文章
3+
* @Author: hutu
4+
* @Date: 2022-01-12 09:29:52
5+
* @LastEditors: hutu
6+
* @LastEditTime: 2022-01-13 10:06:00
7+
*/
8+
import * as Mock from 'mockjs'
9+
import { IArticleList, IArticleListQuery } from '@/interface'
10+
11+
const List: IArticleList[] = []
12+
const count = 100
13+
for (let i = 0; i < count; i++) {
14+
List.push(
15+
Mock.mock({
16+
id: '@increment',
17+
title: '@title(5, 10)',
18+
author: '@first',
19+
'type|1': ['vue', 'Laravel', 'react', 'thinkphp'],
20+
'status|1': ['published', 'draft'],
21+
pageviews: '@integer(300, 5000)',
22+
created_at: '@datetime'
23+
})
24+
)
25+
}
26+
27+
export const article = [
28+
{
29+
url: '/api/article/list',
30+
type: 'get',
31+
response: (config: { body: IArticleListQuery }) => {
32+
const { type, title, page = 1, limit = 20, sort } = config.body
33+
let mockList = List.filter((item) => {
34+
if (type && item.type !== type) return false
35+
if (title && item.title.indexOf(title) < 0) return false
36+
return true
37+
})
38+
39+
if (sort === '-id') {
40+
mockList = mockList.reverse()
41+
}
42+
const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))
43+
return {
44+
code: 10000,
45+
data: {
46+
total: mockList.length,
47+
items: pageList
48+
}
49+
}
50+
}
51+
}
52+
]

src/mock/index.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import Mock from 'mockjs'
2+
import { article } from './article'
3+
import { param2Obj } from './utils'
4+
5+
type IOptions = {
6+
url: string
7+
type: string
8+
body: string
9+
}
10+
const mocks = [...article]
11+
12+
function mockXHR() {
13+
Mock.XHR.prototype.proxy_send = Mock.XHR.prototype.send
14+
Mock.XHR.prototype.send = function () {
15+
if (this.custom.xhr) {
16+
this.custom.xhr.withCredentials = this.withCredentials || false
17+
18+
if (this.responseType) {
19+
this.custom.xhr.responseType = this.responseType
20+
}
21+
}
22+
this.proxy_send(...arguments)
23+
}
24+
// : { (config: any): { code: number; data: { total: number; items: any[] } }; (arg0: { method: string; body: any; query: IDictionary<string> }): any }
25+
function XHR2ExpressReqWrap(respond) {
26+
return function (options: IOptions) {
27+
let result = null
28+
if (respond instanceof Function) {
29+
const { body, type, url } = options
30+
result = respond({
31+
method: type,
32+
body: JSON.parse(body),
33+
query: param2Obj(url)
34+
})
35+
} else {
36+
result = respond
37+
}
38+
return Mock.mock(result)
39+
}
40+
}
41+
42+
for (const i of mocks) {
43+
Mock.mock(new RegExp(i.url), i.type || 'get', XHR2ExpressReqWrap(i.response))
44+
}
45+
}
46+
mockXHR()

src/mock/utils.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* @Description:
3+
* @Author: hutu
4+
* @Date: 2022-01-12 14:16:11
5+
* @LastEditors: hutu
6+
* @LastEditTime: 2022-01-12 14:18:12
7+
*/
8+
import { IDictionary } from '@/interface'
9+
10+
/**
11+
* @desc: 获取url上的参数
12+
* @param {string} url 请求路径
13+
* @return {object}
14+
*/
15+
export function param2Obj(url: string) {
16+
const search = decodeURIComponent(url.split('?')[1]).replace(/\+/g, ' ')
17+
if (!search) {
18+
return {}
19+
}
20+
const obj: IDictionary<string> = {}
21+
const searchArr = search.split('&')
22+
searchArr.forEach((v) => {
23+
const index = v.indexOf('=')
24+
if (index !== -1) {
25+
const name = v.substring(0, index)
26+
const val = v.substring(index + 1, v.length)
27+
obj[name] = val
28+
}
29+
})
30+
return obj
31+
}

0 commit comments

Comments
 (0)