1.2.3 后台操作按钮调整及其新增开启拼团功能
This commit is contained in:
55
src/mixins/initData.js
Normal file
55
src/mixins/initData.js
Normal file
@ -0,0 +1,55 @@
|
||||
import { initData } from '@/api/data'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
loading: true, data: [], page: 0, size: 10, total: 0, url: '', params: {}, query: {}, time: 170, isAdd: false
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async init() {
|
||||
if (!await this.beforeInit()) {
|
||||
return
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
this.loading = true
|
||||
initData(this.url, this.params).then(res => {
|
||||
this.total = res.totalElements
|
||||
this.data = res.content
|
||||
setTimeout(() => {
|
||||
this.loading = false
|
||||
}, this.time)
|
||||
resolve(res)
|
||||
}).catch(err => {
|
||||
this.loading = false
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
},
|
||||
beforeInit() {
|
||||
return true
|
||||
},
|
||||
pageChange(e) {
|
||||
this.page = e - 1
|
||||
this.init()
|
||||
},
|
||||
sizeChange(e) {
|
||||
this.page = 0
|
||||
this.size = e
|
||||
this.init()
|
||||
},
|
||||
// 预防删除第二页最后一条数据时,或者多选删除第二页的数据时,页码错误导致请求无数据
|
||||
dleChangePage(size) {
|
||||
if (size === undefined) {
|
||||
size = 1
|
||||
}
|
||||
if (this.data.length === size && this.page !== 0) {
|
||||
this.page = this.page - 1
|
||||
}
|
||||
},
|
||||
toQuery() {
|
||||
this.page = 0
|
||||
this.init()
|
||||
}
|
||||
}
|
||||
}
|
41
src/mixins/initDict.js
Normal file
41
src/mixins/initDict.js
Normal file
@ -0,0 +1,41 @@
|
||||
import { get, getDictMap } from '@/api/dictDetail'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
dicts: [], dictMap: {}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async getDict(name) {
|
||||
return new Promise((resolve, reject) => {
|
||||
get(name).then(res => {
|
||||
this.dicts = res.content
|
||||
resolve(res)
|
||||
}).catch(err => {
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
},
|
||||
// 多个字典查询时使用逗号拼接, 如:
|
||||
// 加载多个数据字典,如何调用如下:
|
||||
// this.getDict('user_status,job_status')
|
||||
// 在vue中使用加载出来的字典:
|
||||
// dictMap.[字典名称] 如:dictMap.user_status、 dictMap.job_status
|
||||
async getDictMap(names) {
|
||||
// 优先放入到dictMap中,避免页面加载时 undefined
|
||||
const arr = names.split(',')
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
this.dictMap[arr[i]] = []
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
getDictMap(names).then(res => {
|
||||
this.dictMap = res
|
||||
resolve(res)
|
||||
}).catch(err => {
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user