Skip to content

Commit 5142e6e

Browse files
feat: 🎸 综合实例重构中
1 parent 35879f8 commit 5142e6e

File tree

16 files changed

+634
-61
lines changed

16 files changed

+634
-61
lines changed

mock/example/index.ts

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,28 @@
11
import Mock from 'mockjs'
22
import { toAnyString } from '@/utils'
33

4-
const List: any[] = []
4+
let List: any[] = []
55
const count = 100
66

77
const baseContent = '<p>I am testing data, I am testing data.</p><p><img src="https://wpimg.wallstcn.com/4c69009c-0fd4-4153-b112-6cb53d1cf943"></p>'
8-
const image_uri = 'https://wpimg.wallstcn.com/e4558086-631c-425c-9430-56ffb46e70b3'
8+
// const image_uri = 'https://wpimg.wallstcn.com/e4558086-631c-425c-9430-56ffb46e70b3'
99

1010
for (let i = 0; i < count; i++) {
1111
List.push(Mock.mock({
1212
id: toAnyString(),
13-
timestamp: +Mock.Random.date('T'),
13+
// timestamp: +Mock.Random.date('T'),
1414
author: '@first',
15-
reviewer: '@first',
1615
title: '@title(5, 10)',
17-
content_short: 'mock data',
1816
content: baseContent,
19-
forecast: '@float(0, 100, 2, 2)',
2017
importance: '@integer(1, 3)',
21-
'type|1': ['CN', 'US', 'JP', 'EU'],
22-
'status|1': ['published', 'draft', 'deleted'],
2318
display_time: '@datetime',
24-
comment_disabled: true,
25-
pageviews: '@integer(300, 5000)',
26-
image_uri,
27-
platforms: ['a-platform']
19+
pageviews: '@integer(300, 5000)'
20+
// image_uri
2821
}))
2922
}
3023

3124
export default [
25+
// 列表接口
3226
{
3327
url: 'http://mockjs.test.cn/example/list',
3428
type: 'get',
@@ -51,17 +45,33 @@ export default [
5145
}
5246
},
5347

48+
// 删除接口
5449
{
5550
url: 'http://mockjs.test.cn/example/delete',
5651
type: 'post',
5752
response: (config: any) => {
58-
return {
59-
code: '0000',
60-
data: '删除成功'
53+
const ids = config.body.ids
54+
if (!ids) {
55+
return {
56+
code: '500',
57+
message: '请选择需要删除的数据'
58+
}
59+
} else {
60+
let i = List.length
61+
while (i--) {
62+
if (ids.indexOf(List[i].id) !== -1) {
63+
List.splice(i, 1)
64+
}
65+
}
66+
return {
67+
code: '0000',
68+
data: 'success'
69+
}
6170
}
6271
}
6372
},
6473

74+
// 详情接口
6575
{
6676
url: 'http://mockjs.test.cn/example/detail',
6777
type: 'get',
@@ -78,13 +88,34 @@ export default [
7888
}
7989
},
8090

91+
// 保存接口
8192
{
8293
url: 'http://mockjs.test.cn/example/save',
8394
type: 'post',
8495
response: (config: any) => {
85-
return {
86-
code: '0000',
87-
data: 'success'
96+
const data = config.body
97+
if (!data.id) {
98+
List = [Object.assign(data, { id: toAnyString(), importance: Number(data.importance) })].concat(List)
99+
return {
100+
code: '0000',
101+
data: 'success'
102+
}
103+
} else {
104+
List.map(item => {
105+
if (item.id === data.id) {
106+
for (const key in item) {
107+
if (key === 'importance') {
108+
item[key] = Number(data[key])
109+
} else {
110+
item[key] = data[key]
111+
}
112+
}
113+
}
114+
})
115+
return {
116+
code: '0000',
117+
data: 'success'
118+
}
88119
}
89120
}
90121
}

src/components/Dialog/index.vue

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<template>
2+
<el-dialog
3+
v-bind="getBindValue"
4+
destroy-on-close
5+
:close-on-click-modal="false"
6+
top="10vh"
7+
>
8+
<template v-if="slots.title" #title>
9+
<slot name="title" />
10+
</template>
11+
12+
<!-- 弹窗内容 -->
13+
<el-scrollbar class="com-dialog__content">
14+
<slot />
15+
</el-scrollbar>
16+
17+
<template v-if="slots.footer" #footer>
18+
<slot name="footer" />
19+
</template>
20+
</el-dialog>
21+
</template>
22+
23+
<script lang="ts">
24+
import { defineComponent, computed } from 'vue'
25+
export default defineComponent({
26+
name: 'Dialog',
27+
setup(props, { slots, attrs }) {
28+
const getBindValue = computed((): any => {
29+
const bindValue = { ...attrs, ...props }
30+
return bindValue
31+
})
32+
33+
return {
34+
getBindValue,
35+
slots
36+
}
37+
}
38+
})
39+
</script>
40+
41+
<style lang="less" scoped>
42+
.com-dialog__content {
43+
height: 600px;
44+
}
45+
</style>

src/components/Editor/props.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const editorProps = {
1111
default: () => {
1212
return {
1313
height: 500,
14-
zIndex: 500,
14+
zIndex: 0,
1515
placeholder: '请输入文本',
1616
focus: false,
1717
onchangeTimeout: 500,

src/components/Table/index.vue

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
<el-table-column
66
v-if="selection"
77
type="selection"
8-
width="55"
8+
:reserve-selection="reserveSelection"
9+
width="40"
910
/>
1011
<template v-for="item in columns">
1112
<!-- 自定义索引 -->
@@ -85,17 +86,25 @@ export default defineComponent({
8586
TableColumn
8687
},
8788
props: {
89+
// 表头
8890
columns: {
8991
type: Array as PropType<any[]>,
9092
default: () => []
9193
},
94+
// 是否多选
9295
selection: {
9396
type: Boolean as PropType<boolean>,
9497
default: false
9598
},
99+
// 是否展示分页
96100
pagination: {
97101
type: [Boolean, Object] as PropType<boolean | object>,
98102
default: false
103+
},
104+
// 仅对 type=selection 的列有效,类型为 Boolean,为 true 则会在数据更新之后保留之前选中的数据(需指定 row-key)
105+
reserveSelection: {
106+
type: Boolean as PropType<boolean>,
107+
default: false
99108
}
100109
},
101110
setup(props, { attrs, slots }) {
@@ -137,7 +146,7 @@ export default defineComponent({
137146
}
138147
})
139148
140-
function headerDragend(newWidth: number, oldWidth: number, column: any, event: any) {
149+
function headerDragend(newWidth: number, oldWidth: number, column: any) {
141150
// 不懂为啥无法自动计算宽度,只能手动去计算了。。失望ing,到时候看看能不能优化吧。
142151
const htmlArr = document.getElementsByClassName(column.id)
143152
for (const v of htmlArr) {

src/components/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { App } from 'vue'
2-
// import Button from '@/components/Button/index.vue'// Button组件
2+
import Dialog from './Dialog/index.vue'// Dialog组件
33

44
export function setupGlobCom(app: App<Element>): void {
5-
// app.component('AButton', Button)
5+
app.component('ComDialog', Dialog)
66
}

src/hooks/useExample.ts

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,88 @@
11
// 常用的增删改查 hook
22
import { reactive, ref } from 'vue'
3+
import { ElMessageBox } from 'element-plus'
4+
import { Message } from '_c/Message'
35

46
interface DefalutParams {
5-
pageIndex: number
6-
pageSize: number
7+
pageIndex: number // 页码
8+
pageSize: number // 页数
9+
}
10+
11+
interface DelsParmas {
12+
noDataText?: string // 没有选中数据时的提示
13+
text?: string // 删除前的提示
14+
hiddenVerify?: boolean // 是否隐藏前置判断
715
}
816

917
export function useExample() {
18+
// 请求接口的基本参数
1019
const defalutParams = reactive<DefalutParams>({
1120
pageIndex: 1,
1221
pageSize: 10
1322
})
14-
23+
24+
// 多选数据
25+
const selectionData = ref<any[]>([])
26+
27+
// 表格数据
1528
const tableData = ref<any[]>([])
16-
29+
30+
// 表格加载状态
1731
const loading = ref<boolean>(true)
1832

33+
// 表格总条数
1934
const total = ref<number>(0)
20-
35+
36+
// 是否展示弹窗
37+
const dialogVisible = ref<boolean>(false)
38+
39+
// 弹窗标题
40+
const title = ref<string>('')
41+
42+
// 表格展示条目改变时候重置基本参数
2143
function sizeChange(val: number) {
2244
loading.value = true
2345
defalutParams.pageIndex = 1
2446
defalutParams.pageSize = val
2547
}
26-
48+
49+
// 表格分页改变时候重置基本参数
2750
function currentChange(val: number) {
2851
loading.value = true
2952
defalutParams.pageIndex = val
3053
}
3154

55+
// 删除多选
56+
function delData(callBack: Function, config?: DelsParmas) {
57+
if (selectionData.value.length === 0 && !config?.hiddenVerify) {
58+
Message.warning(config?.noDataText || '请选择需要删除的数据!')
59+
return
60+
}
61+
ElMessageBox.confirm(config?.text || '此操作将永久删除选中数据, 是否继续?', '提示', {
62+
confirmButtonText: '确定',
63+
cancelButtonText: '取消',
64+
type: 'warning'
65+
}).then(async() => {
66+
await callBack()
67+
})
68+
}
69+
70+
// 多选变化的时候
71+
function handleSelectionChange(selection: any[]) {
72+
selectionData.value = selection
73+
}
74+
3275
return {
3376
defalutParams,
3477
tableData,
78+
selectionData,
3579
loading,
3680
total,
81+
dialogVisible,
82+
title,
3783
sizeChange,
38-
currentChange
84+
currentChange,
85+
delData,
86+
handleSelectionChange
3987
}
4088
}

src/pages/index/api/modules/example.ts

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

src/pages/index/router/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,14 @@ export const asyncRouterMap: AppRouteRecordRaw[] = [
170170
meta: {
171171
title: 'markdown编辑器'
172172
}
173+
},
174+
{
175+
path: 'dialog',
176+
component: () => import('_p/index/views/components-demo/dialog/index.vue'),
177+
name: 'DialogDemo',
178+
meta: {
179+
title: '弹窗'
180+
}
173181
}
174182
]
175183
},

src/pages/index/store/modules/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class App extends VuexModule implements AppState {
2828
// public fixedTags = true // 是否固定标签栏
2929
// public fixedNavbar = true // 是否固定navbar
3030
public fixedHeader = true // 是否固定header
31-
public layout = 'Top' // layout布局
31+
public layout = 'Classic' // layout布局
3232
public showBreadcrumb = true // 是否显示面包屑
3333
public showHamburger = true // 是否显示侧边栏缩收按钮
3434
public showScreenfull = true // 是否全屏按钮

0 commit comments

Comments
 (0)