Commit 1f358dcd by cwq0219

接口-优化

1 parent c70f5844
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<div class="d2-table"> <div class="d2-table">
<el-table <el-table
:ref="tableParams.mutiSelectName + 'MutiTable' || 'mutiTable'" :ref="tableParams.mutiSelectName + 'MutiTable' || 'mutiTable'"
:data="apiParame ? data : tableData" :data="getListApi ? data : tableData"
:row-key="tableParams.mutiSelectUniqueKey || ''" :row-key="tableParams.mutiSelectUniqueKey || ''"
v-loading="loading" v-loading="loading"
:border="tableParams.border || false" :border="tableParams.border || false"
...@@ -63,7 +63,7 @@ ...@@ -63,7 +63,7 @@
<template v-else-if="item.formatter"> <template v-else-if="item.formatter">
<span v-text="item.formatter(scope.row)"></span> <span v-text="item.formatter(scope.row)"></span>
</template> </template>
<template v-else-if="apiParame"> <template v-else-if="getListApi">
<span v-text="data[scope.$index][item.prop]"></span> <span v-text="data[scope.$index][item.prop]"></span>
</template> </template>
<template v-else> <template v-else>
...@@ -102,7 +102,7 @@ ...@@ -102,7 +102,7 @@
:current-page="page.pageNum" :current-page="page.pageNum"
:page-sizes="[10,20,30,40]" :page-sizes="[10,20,30,40]"
:page-size="page.pageSize" :page-size="page.pageSize"
:total="apiParame ? total : tableTotal" :total="getListApi ? total : tableTotal"
layout="sizes,total,->,prev,pager,next,jumper" layout="sizes,total,->,prev,pager,next,jumper"
> >
</el-pagination> </el-pagination>
...@@ -110,7 +110,6 @@ ...@@ -110,7 +110,6 @@
</template> </template>
<script> <script>
import request from '@/services/request'
export default { export default {
name: 'basic-table', name: 'basic-table',
data() { data() {
...@@ -158,13 +157,9 @@ export default { ...@@ -158,13 +157,9 @@ export default {
default: 10 default: 10
}, },
// 获取列表接口 // 获取列表接口
// getListApi: { getListApi: {
// type: Function, type: Function,
// default: null default: null
// },
apiParame: {
type: Object,
default: () => {}
}, },
// 分页,默认有 // 分页,默认有
hasPage: { hasPage: {
...@@ -223,7 +218,6 @@ export default { ...@@ -223,7 +218,6 @@ export default {
watch: { watch: {
}, },
mounted() { mounted() {
console.log('ccc', this.apiParame)
const btn = document.getElementById(this.tableParams.btnId) const btn = document.getElementById(this.tableParams.btnId)
// this.tableData = [ // this.tableData = [
// { // {
...@@ -237,7 +231,7 @@ export default { ...@@ -237,7 +231,7 @@ export default {
// } // }
// ] // ]
btn && btn.addEventListener('click', this.refreshEmit) btn && btn.addEventListener('click', this.refreshEmit)
this.apiParame && this.refreshTable() this.getListApi && this.refreshTable()
}, },
methods: { methods: {
...@@ -278,10 +272,9 @@ export default { ...@@ -278,10 +272,9 @@ export default {
params.sortColum = this.sortColum params.sortColum = this.sortColum
params.sort = this.sort === 'descending' ? 1 : 0 params.sort = this.sort === 'descending' ? 1 : 0
} }
request(this.apiParame.apiUrl, this.apiParame.method || 'get', params).then(res => { this.getListApi(params).then(res => {
var data = res.data var data = res.data
this.data = data[this.tableParams.listName] this.data = data[this.tableParams.listName]
console.log(this.data)
this.total = data.total this.total = data.total
this.loading = false this.loading = false
}).catch(() => { }).catch(() => {
...@@ -292,12 +285,12 @@ export default { ...@@ -292,12 +285,12 @@ export default {
// 页码 // 页码
handleSizeChange(value) { handleSizeChange(value) {
this.page.pageSize = value this.page.pageSize = value
this.apiParame ? this.refreshTable(false) : this.$emit('refreshTable', this.page) this.getListApi ? this.refreshTable(false) : this.$emit('refreshTable', this.page)
}, },
handleCurrentChange(value) { handleCurrentChange(value) {
this.page.pageNum = value this.page.pageNum = value
this.apiParame ? this.refreshTable(false) : this.$emit('refreshTable', this.page) this.getListApi ? this.refreshTable(false) : this.$emit('refreshTable', this.page)
} }
} }
} }
......
...@@ -17,10 +17,7 @@ const API = { ...@@ -17,10 +17,7 @@ const API = {
} }
const USER_API = { const USER_API = {
USER_SEARCH: { USER_SEARCH: BASE_URL + '/usercenter/user/search',
apiUrl: BASE_URL + '/usercenter/user/search'
// method: 'post'
},
USER_SUPER: BASE_URL + '/usercenter/user/suitableSuperUsers', USER_SUPER: BASE_URL + '/usercenter/user/suitableSuperUsers',
USER_ADD: BASE_URL + '/usercenter/user/add' USER_ADD: BASE_URL + '/usercenter/user/add'
} }
......
...@@ -2,11 +2,11 @@ import HTTP from '@/utils/http' ...@@ -2,11 +2,11 @@ import HTTP from '@/utils/http'
const axiosHttp = new HTTP() const axiosHttp = new HTTP()
function request(url = '', method = 'GET', data = {}) { function request(data = {}, method = 'GET') {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
var reqMethod = method.toLocaleLowerCase() === 'get' ? 'axiosGet' : 'axiosPost' var reqMethod = method.toLocaleLowerCase() === 'get' ? 'axiosGet' : 'axiosPost'
axiosHttp[reqMethod]({ axiosHttp[reqMethod]({
url: url, url: data.url,
data: data, data: data,
success(data) { success(data) {
resolve(data) resolve(data)
......
import HTTP from '@/utils/http' import {
import { USER_API } from '@/config/config' USER_API
} from '@/config/config'
import request from '@/services/request'
export default class UserService extends HTTP { // 获取用户列表
// 获取用户列表 function getUserList(params) {
getUserList () { params.url = USER_API.USER_SEARCH
return new Promise((resolve, reject) => { return request(params)
this.axiosGet({
url: USER_API.USER_SEARCH,
data: {},
success(data) {
resolve(data)
},
error(error) {
// 网络请求失败
console.log('网络请求失败')
// window.location.reload()
}
})
})
}
// 获取上级树
getSuperUser (params) {
return new Promise((resolve, reject) => {
this.axiosGet({
url: USER_API.USER_SUPER,
data: {params},
success(data) {
resolve(data)
},
error(error) {
// 网络请求失败
console.log('网络请求失败')
}
})
})
}
// 新增用户
addUser (params) {
return new Promise((resolve, reject) => {
this.axiosGet({
url: USER_API.USER_SUPER,
data: {params},
success(data) {
resolve(data)
},
error(error) {
// 网络请求失败
console.log('网络请求失败')
}
})
})
}
} }
// 获取上级树
function getSuperUser(params) {
params.url = USER_API.USER_SUPER
return request(params)
}
// 新增用户
function addUser(params) {
params.url = USER_API.USER_ADD
return request(params)
}
export {
getUserList,
getSuperUser,
addUser
}
\ No newline at end of file \ No newline at end of file
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
<basic-table <basic-table
:tableParams="tableParams" :tableParams="tableParams"
:searchForm="searchForm" :searchForm="searchForm"
:apiParame="apiParame" :getListApi="getListApi"
:hasNum="false" :hasNum="false"
> >
<span <span
...@@ -114,12 +114,9 @@ ...@@ -114,12 +114,9 @@
</template> </template>
<script> <script>
import { // import UserService from 'services/user';
USER_API import {getUserList, getSuperUser, addUser } from 'services/user';
} from '@/config/config'
import UserService from 'services/user';
import OrginizaService from 'services/orginizaManage'; import OrginizaService from 'services/orginizaManage';
const userService = new UserService();
const orginizaService = new OrginizaService(); const orginizaService = new OrginizaService();
export default { export default {
data() { data() {
...@@ -193,8 +190,7 @@ export default { ...@@ -193,8 +190,7 @@ export default {
] ]
} }
}, },
apiParame: USER_API.USER_SEARCH, getListApi: getUserList,
// getListApi: getUserList,
// 折叠菜单数据 // 折叠菜单数据
data: [], data: [],
// 弹窗数据 // 弹窗数据
...@@ -417,7 +413,7 @@ export default { ...@@ -417,7 +413,7 @@ export default {
}, },
// 获取上级树 // 获取上级树
getSuperUser(params) { getSuperUser(params) {
userService.getSuperUser(params).then(res => { getSuperUser(params).then(res => {
console.log(res) console.log(res)
this.filterTextData = res.data.list this.filterTextData = res.data.list
}) })
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!