VueTable
This commit is contained in:
27
vue-table/store/index.js
Normal file
27
vue-table/store/index.js
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* @Author: your name
|
||||
* @Date: 2020-09-07 10:17:01
|
||||
* @LastEditTime: 2021-02-18 14:51:58
|
||||
* @LastEditors: Please set LastEditors
|
||||
* @Description: In User Settings Edit,
|
||||
* @FilePath: \dbadmin\src\store\index.js
|
||||
*/
|
||||
import Vue from 'vue'
|
||||
import Vuex from 'vuex'
|
||||
import query from './modules/query'
|
||||
|
||||
Vue.use(Vuex)
|
||||
|
||||
const store = new Vuex.Store({
|
||||
modules: {
|
||||
app,
|
||||
api,
|
||||
user,
|
||||
tagsView,
|
||||
permission,
|
||||
query
|
||||
},
|
||||
getters
|
||||
})
|
||||
|
||||
export default store
|
88
vue-table/store/modules/query.js
Normal file
88
vue-table/store/modules/query.js
Normal file
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* @Author: your name
|
||||
* @Date: 2020-10-28 14:40:52
|
||||
* @LastEditTime: 2020-12-29 14:33:05
|
||||
* @LastEditors: Please set LastEditors
|
||||
* @Description: In User Settings Edit
|
||||
* @FilePath: \dbadmin\src\store\modules\query.js
|
||||
*/
|
||||
import { Module, VuexModule, Mutation } from 'vuex-module-decorators'
|
||||
|
||||
export const DEFAULT_TAG = 'default'
|
||||
|
||||
function nullObj() {
|
||||
return Object.create(null)
|
||||
}
|
||||
|
||||
@Module({ name: 'query', namespaced: true })
|
||||
class Query extends VuexModule {
|
||||
data = nullObj()
|
||||
|
||||
pageData = nullObj()
|
||||
|
||||
fetchs = nullObj()
|
||||
|
||||
@Mutation
|
||||
init(data) {
|
||||
let path = ''
|
||||
let initData = nullObj()
|
||||
let tag = DEFAULT_TAG
|
||||
if (typeof data === 'string') {
|
||||
path = data
|
||||
} else if (typeof data === 'object') {
|
||||
if (data.path) path = data.path
|
||||
if (data.initData) initData = data.initData
|
||||
if (data.tag) tag = data.tag
|
||||
}
|
||||
if (!path) throw new Error('path不能为空')
|
||||
initPath.call(this, path)
|
||||
if (!this.data[path][tag]) {
|
||||
this.data[path][tag] = initData
|
||||
}
|
||||
if (!this.pageData[path][tag]) {
|
||||
this.pageData[path][tag] = {
|
||||
page: 1,
|
||||
size: 20
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Mutation
|
||||
setData({ path, data, tag = DEFAULT_TAG }) {
|
||||
initPath.call(this, path)
|
||||
this.data[path][tag] = data
|
||||
}
|
||||
|
||||
@Mutation
|
||||
registerFetch({ path, func, tag = DEFAULT_TAG }) {
|
||||
initPath.call(this, path)
|
||||
this.fetchs[path][tag] = func
|
||||
}
|
||||
|
||||
@Mutation
|
||||
unregisterFetch(path, tag = DEFAULT_TAG) {
|
||||
initPath.call(this, path)
|
||||
delete this.fetchs[path][tag]
|
||||
}
|
||||
}
|
||||
|
||||
function initPath(path) {
|
||||
if (this instanceof Window) {
|
||||
throw new Error('initPath this对象没有绑定')
|
||||
}
|
||||
if (!this.data[path]) this.data[path] = nullObj()
|
||||
if (!this.pageData[path]) this.pageData[path] = nullObj()
|
||||
if (!this.fetchs[path]) this.fetchs[path] = nullObj()
|
||||
}
|
||||
|
||||
// function initTag(path, tag) {
|
||||
// if (this instanceof Window) {
|
||||
// throw new Error('initPath this对象没有绑定')
|
||||
// }
|
||||
// initTag.call(path)
|
||||
// if (!this.data[path][tag]) this.data[path][tag] = nullObj()
|
||||
// if (!this.pageData[path][tag]) this.pageData[path][tag] = nullObj()
|
||||
// if (!this.fetchs[path][tag]) this.fetchs[path][tag] = nullObj()
|
||||
// }
|
||||
|
||||
export default Query
|
Reference in New Issue
Block a user