From 5142e6e323cb20c89a97398bf41d32c93ce42cad Mon Sep 17 00:00:00 2001
From: chenkl <321200875@qq.com>
Date: Wed, 23 Dec 2020 17:29:17 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20=E7=BB=BC=E5=90=88?=
=?UTF-8?q?=E5=AE=9E=E4=BE=8B=E9=87=8D=E6=9E=84=E4=B8=AD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
mock/example/index.ts | 67 +++++--
src/components/Dialog/index.vue | 45 +++++
src/components/Editor/props.ts | 2 +-
src/components/Table/index.vue | 13 +-
src/components/index.ts | 4 +-
src/hooks/useExample.ts | 62 +++++-
src/pages/index/api/modules/example.ts | 18 --
src/pages/index/router/index.ts | 8 +
src/pages/index/store/modules/app.ts | 2 +-
.../views/components-demo/dialog/index.vue | 38 ++++
.../index/views/example-demo/example/api.ts | 22 +++
.../example/components/IfnoWrite.vue | 182 ++++++++++++++++++
.../example-demo/example/components/types.ts | 18 ++
.../views/example-demo/example/index.vue | 172 +++++++++++++++--
src/styles/glob.less | 16 +-
src/utils/index.ts | 28 +++
16 files changed, 635 insertions(+), 62 deletions(-)
create mode 100644 src/components/Dialog/index.vue
delete mode 100644 src/pages/index/api/modules/example.ts
create mode 100644 src/pages/index/views/components-demo/dialog/index.vue
create mode 100644 src/pages/index/views/example-demo/example/api.ts
create mode 100644 src/pages/index/views/example-demo/example/components/IfnoWrite.vue
create mode 100644 src/pages/index/views/example-demo/example/components/types.ts
diff --git a/mock/example/index.ts b/mock/example/index.ts
index d6d6893..ace8349 100644
--- a/mock/example/index.ts
+++ b/mock/example/index.ts
@@ -1,34 +1,28 @@
import Mock from 'mockjs'
import { toAnyString } from '@/utils'
-const List: any[] = []
+let List: any[] = []
const count = 100
const baseContent = '
I am testing data, I am testing data.

'
-const image_uri = 'https://wpimg.wallstcn.com/e4558086-631c-425c-9430-56ffb46e70b3'
+// const image_uri = 'https://wpimg.wallstcn.com/e4558086-631c-425c-9430-56ffb46e70b3'
for (let i = 0; i < count; i++) {
List.push(Mock.mock({
id: toAnyString(),
- timestamp: +Mock.Random.date('T'),
+ // timestamp: +Mock.Random.date('T'),
author: '@first',
- reviewer: '@first',
title: '@title(5, 10)',
- content_short: 'mock data',
content: baseContent,
- forecast: '@float(0, 100, 2, 2)',
importance: '@integer(1, 3)',
- 'type|1': ['CN', 'US', 'JP', 'EU'],
- 'status|1': ['published', 'draft', 'deleted'],
display_time: '@datetime',
- comment_disabled: true,
- pageviews: '@integer(300, 5000)',
- image_uri,
- platforms: ['a-platform']
+ pageviews: '@integer(300, 5000)'
+ // image_uri
}))
}
export default [
+ // 列表接口
{
url: 'http://mockjs.test.cn/example/list',
type: 'get',
@@ -51,17 +45,33 @@ export default [
}
},
+ // 删除接口
{
url: 'http://mockjs.test.cn/example/delete',
type: 'post',
response: (config: any) => {
- return {
- code: '0000',
- data: '删除成功'
+ const ids = config.body.ids
+ if (!ids) {
+ return {
+ code: '500',
+ message: '请选择需要删除的数据'
+ }
+ } else {
+ let i = List.length
+ while (i--) {
+ if (ids.indexOf(List[i].id) !== -1) {
+ List.splice(i, 1)
+ }
+ }
+ return {
+ code: '0000',
+ data: 'success'
+ }
}
}
},
+ // 详情接口
{
url: 'http://mockjs.test.cn/example/detail',
type: 'get',
@@ -78,13 +88,34 @@ export default [
}
},
+ // 保存接口
{
url: 'http://mockjs.test.cn/example/save',
type: 'post',
response: (config: any) => {
- return {
- code: '0000',
- data: 'success'
+ const data = config.body
+ if (!data.id) {
+ List = [Object.assign(data, { id: toAnyString(), importance: Number(data.importance) })].concat(List)
+ return {
+ code: '0000',
+ data: 'success'
+ }
+ } else {
+ List.map(item => {
+ if (item.id === data.id) {
+ for (const key in item) {
+ if (key === 'importance') {
+ item[key] = Number(data[key])
+ } else {
+ item[key] = data[key]
+ }
+ }
+ }
+ })
+ return {
+ code: '0000',
+ data: 'success'
+ }
}
}
}
diff --git a/src/components/Dialog/index.vue b/src/components/Dialog/index.vue
new file mode 100644
index 0000000..7784715
--- /dev/null
+++ b/src/components/Dialog/index.vue
@@ -0,0 +1,45 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/components/Editor/props.ts b/src/components/Editor/props.ts
index c53c1d1..2c42310 100644
--- a/src/components/Editor/props.ts
+++ b/src/components/Editor/props.ts
@@ -11,7 +11,7 @@ export const editorProps = {
default: () => {
return {
height: 500,
- zIndex: 500,
+ zIndex: 0,
placeholder: '请输入文本',
focus: false,
onchangeTimeout: 500,
diff --git a/src/components/Table/index.vue b/src/components/Table/index.vue
index f76586f..2afcfc2 100644
--- a/src/components/Table/index.vue
+++ b/src/components/Table/index.vue
@@ -5,7 +5,8 @@
@@ -85,17 +86,25 @@ export default defineComponent({
TableColumn
},
props: {
+ // 表头
columns: {
type: Array as PropType,
default: () => []
},
+ // 是否多选
selection: {
type: Boolean as PropType,
default: false
},
+ // 是否展示分页
pagination: {
type: [Boolean, Object] as PropType,
default: false
+ },
+ // 仅对 type=selection 的列有效,类型为 Boolean,为 true 则会在数据更新之后保留之前选中的数据(需指定 row-key)
+ reserveSelection: {
+ type: Boolean as PropType,
+ default: false
}
},
setup(props, { attrs, slots }) {
@@ -137,7 +146,7 @@ export default defineComponent({
}
})
- function headerDragend(newWidth: number, oldWidth: number, column: any, event: any) {
+ function headerDragend(newWidth: number, oldWidth: number, column: any) {
// 不懂为啥无法自动计算宽度,只能手动去计算了。。失望ing,到时候看看能不能优化吧。
const htmlArr = document.getElementsByClassName(column.id)
for (const v of htmlArr) {
diff --git a/src/components/index.ts b/src/components/index.ts
index f647c1c..62ff907 100644
--- a/src/components/index.ts
+++ b/src/components/index.ts
@@ -1,6 +1,6 @@
import type { App } from 'vue'
-// import Button from '@/components/Button/index.vue'// Button组件
+import Dialog from './Dialog/index.vue'// Dialog组件
export function setupGlobCom(app: App): void {
- // app.component('AButton', Button)
+ app.component('ComDialog', Dialog)
}
diff --git a/src/hooks/useExample.ts b/src/hooks/useExample.ts
index 5b21839..0bfb38b 100644
--- a/src/hooks/useExample.ts
+++ b/src/hooks/useExample.ts
@@ -1,40 +1,88 @@
// 常用的增删改查 hook
import { reactive, ref } from 'vue'
+import { ElMessageBox } from 'element-plus'
+import { Message } from '_c/Message'
interface DefalutParams {
- pageIndex: number
- pageSize: number
+ pageIndex: number // 页码
+ pageSize: number // 页数
+}
+
+interface DelsParmas {
+ noDataText?: string // 没有选中数据时的提示
+ text?: string // 删除前的提示
+ hiddenVerify?: boolean // 是否隐藏前置判断
}
export function useExample() {
+ // 请求接口的基本参数
const defalutParams = reactive({
pageIndex: 1,
pageSize: 10
})
-
+
+ // 多选数据
+ const selectionData = ref([])
+
+ // 表格数据
const tableData = ref([])
-
+
+ // 表格加载状态
const loading = ref(true)
+ // 表格总条数
const total = ref(0)
-
+
+ // 是否展示弹窗
+ const dialogVisible = ref(false)
+
+ // 弹窗标题
+ const title = ref('')
+
+ // 表格展示条目改变时候重置基本参数
function sizeChange(val: number) {
loading.value = true
defalutParams.pageIndex = 1
defalutParams.pageSize = val
}
-
+
+ // 表格分页改变时候重置基本参数
function currentChange(val: number) {
loading.value = true
defalutParams.pageIndex = val
}
+ // 删除多选
+ function delData(callBack: Function, config?: DelsParmas) {
+ if (selectionData.value.length === 0 && !config?.hiddenVerify) {
+ Message.warning(config?.noDataText || '请选择需要删除的数据!')
+ return
+ }
+ ElMessageBox.confirm(config?.text || '此操作将永久删除选中数据, 是否继续?', '提示', {
+ confirmButtonText: '确定',
+ cancelButtonText: '取消',
+ type: 'warning'
+ }).then(async() => {
+ await callBack()
+ })
+ }
+
+ // 多选变化的时候
+ function handleSelectionChange(selection: any[]) {
+ selectionData.value = selection
+ }
+
return {
defalutParams,
tableData,
+ selectionData,
loading,
total,
+ dialogVisible,
+ title,
sizeChange,
- currentChange
+ currentChange,
+ delData,
+ handleSelectionChange
}
}
diff --git a/src/pages/index/api/modules/example.ts b/src/pages/index/api/modules/example.ts
deleted file mode 100644
index 710cfb3..0000000
--- a/src/pages/index/api/modules/example.ts
+++ /dev/null
@@ -1,18 +0,0 @@
-import { fetch } from '../../axios-config/axios'
-
-import { AxiosPromise } from 'axios'
-
-import { EmptyObjFun } from '@/types/glob'
-
-interface PropsData {
- params?: any
- data?: any
-}
-
-const methods: EmptyObjFun = {
- getExampleList: function({ params }: PropsData): AxiosPromise {
- return fetch({ url: '/example/list', method: 'get', params })
- }
-}
-
-export default methods
diff --git a/src/pages/index/router/index.ts b/src/pages/index/router/index.ts
index 9e29a88..721975c 100644
--- a/src/pages/index/router/index.ts
+++ b/src/pages/index/router/index.ts
@@ -170,6 +170,14 @@ export const asyncRouterMap: AppRouteRecordRaw[] = [
meta: {
title: 'markdown编辑器'
}
+ },
+ {
+ path: 'dialog',
+ component: () => import('_p/index/views/components-demo/dialog/index.vue'),
+ name: 'DialogDemo',
+ meta: {
+ title: '弹窗'
+ }
}
]
},
diff --git a/src/pages/index/store/modules/app.ts b/src/pages/index/store/modules/app.ts
index 7bcbaad..ee3b584 100644
--- a/src/pages/index/store/modules/app.ts
+++ b/src/pages/index/store/modules/app.ts
@@ -28,7 +28,7 @@ class App extends VuexModule implements AppState {
// public fixedTags = true // 是否固定标签栏
// public fixedNavbar = true // 是否固定navbar
public fixedHeader = true // 是否固定header
- public layout = 'Top' // layout布局
+ public layout = 'Classic' // layout布局
public showBreadcrumb = true // 是否显示面包屑
public showHamburger = true // 是否显示侧边栏缩收按钮
public showScreenfull = true // 是否全屏按钮
diff --git a/src/pages/index/views/components-demo/dialog/index.vue b/src/pages/index/views/components-demo/dialog/index.vue
new file mode 100644
index 0000000..baddf61
--- /dev/null
+++ b/src/pages/index/views/components-demo/dialog/index.vue
@@ -0,0 +1,38 @@
+
+
+
+
打开弹窗
+
+
+
+ 我是弹窗内容
+
+
+ 取消
+ 确定
+
+
+
+
+
+
+
+
diff --git a/src/pages/index/views/example-demo/example/api.ts b/src/pages/index/views/example-demo/example/api.ts
new file mode 100644
index 0000000..f07d7e3
--- /dev/null
+++ b/src/pages/index/views/example-demo/example/api.ts
@@ -0,0 +1,22 @@
+import { fetch } from '_p/index/axios-config/axios'
+
+interface PropsData {
+ params?: any
+ data?: any
+}
+
+export const getExampleListApi = ({ params }: PropsData): any => {
+ return fetch({ url: '/example/list', method: 'get', params })
+}
+
+export const delsExampApi = ({ data }: PropsData): any => {
+ return fetch({ url: '/example/delete', method: 'post', data })
+}
+
+export const saveExampApi = ({ data }: PropsData): any => {
+ return fetch({ url: '/example/save', method: 'post', data })
+}
+
+export const getExampDetApi = ({ params }: PropsData): any => {
+ return fetch({ url: '/example/detail', method: 'get', params })
+}
diff --git a/src/pages/index/views/example-demo/example/components/IfnoWrite.vue b/src/pages/index/views/example-demo/example/components/IfnoWrite.vue
new file mode 100644
index 0000000..9e0a2c3
--- /dev/null
+++ b/src/pages/index/views/example-demo/example/components/IfnoWrite.vue
@@ -0,0 +1,182 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 取消
+ 保存
+
+
+
+
+
+
+
diff --git a/src/pages/index/views/example-demo/example/components/types.ts b/src/pages/index/views/example-demo/example/components/types.ts
new file mode 100644
index 0000000..2e5d6bb
--- /dev/null
+++ b/src/pages/index/views/example-demo/example/components/types.ts
@@ -0,0 +1,18 @@
+export interface InfoWriteParams {
+ title: string
+ id?: string
+ author: string
+ content: string
+ importance: string
+ display_time: string
+ pageviews: number
+}
+
+export interface InfoWriteRules {
+ title?: any[]
+ author?: any[]
+ content?: any[]
+ importance?: any[]
+ display_time?: any[]
+ pageviews?: any[]
+}
diff --git a/src/pages/index/views/example-demo/example/index.vue b/src/pages/index/views/example-demo/example/index.vue
index 99c18ad..58e467d 100644
--- a/src/pages/index/views/example-demo/example/index.vue
+++ b/src/pages/index/views/example-demo/example/index.vue
@@ -1,7 +1,25 @@
+
+
+
+
+
+ 新增
+ 删除
+
+
+ @selection-change="handleSelectionChange"
+ >
+
+ {{ scope.row.importance === 3
+ ? '重要'
+ : (scope.row.importance === 2
+ ? '良好'
+ : '一般') }}
+
+
+
+ 编辑
+ 删除
+
+
+
+
+
+