Commit 3474f96a by cwq0219

表格-接口

1 parent 15adcd5f
......@@ -43,7 +43,7 @@ export default {
mounted() {
const baseService = new BaseService();
baseService.getBaseConfig().then((res) => {
console.log(res);
// console.log(res);
const baseURL = res.axios.baseURL;
this.updateBaseURL(baseURL);
}, (err) => {
......
......@@ -3,7 +3,7 @@
<div class="d2-table">
<el-table
:ref="tableParams.mutiSelectName + 'MutiTable' || 'mutiTable'"
:data="getListApi ? data : tableData"
:data="apiParame ? data : tableData"
:row-key="tableParams.mutiSelectUniqueKey || ''"
v-loading="loading"
:border="tableParams.border || false"
......@@ -63,7 +63,7 @@
<template v-else-if="item.formatter">
<span v-text="item.formatter(scope.row)"></span>
</template>
<template v-else-if="getListApi">
<template v-else-if="apiParame">
<span v-text="data[scope.$index][item.prop]"></span>
</template>
<template v-else>
......@@ -102,7 +102,7 @@
:current-page="page.pageNum"
:page-sizes="[10,20,30,40]"
:page-size="page.pageSize"
:total="getListApi ? total : tableTotal"
:total="apiParame ? total : tableTotal"
layout="sizes,total,->,prev,pager,next,jumper"
>
</el-pagination>
......@@ -110,6 +110,7 @@
</template>
<script>
import request from '@/services/request'
export default {
name: 'basic-table',
data() {
......@@ -141,15 +142,15 @@ export default {
tableData: {
type: Array,
default: () => [
{
id: 1,
account: '胡悦',
username: 'jkjk',
departmentName: '平台研发中心',
phoneNumber: '1546861321',
enablesStatus: 1,
createDate: '2013556'
}
// {
// id: 1,
// account: '胡悦',
// username: 'jkjk',
// departmentName: '平台研发中心',
// phoneNumber: '1546861321',
// enablesStatus: 1,
// createDate: '2013556'
// }
]
},
tableTotal: {
......@@ -157,9 +158,13 @@ export default {
default: 10
},
// 获取列表接口
getListApi: {
type: Function,
default: null
// getListApi: {
// type: Function,
// default: null
// },
apiParame: {
type: Object,
default: () => {}
},
// 分页,默认有
hasPage: {
......@@ -218,6 +223,7 @@ export default {
watch: {
},
mounted() {
console.log('ccc', this.apiParame)
const btn = document.getElementById(this.tableParams.btnId)
// this.tableData = [
// {
......@@ -231,11 +237,10 @@ export default {
// }
// ]
btn && btn.addEventListener('click', this.refreshEmit)
this.getListApi && this.refreshTable()
this.apiParame && this.refreshTable()
},
methods: {
// 排序
sortChange({ column, prop, order }) {
this.sortColum = order ? prop : ''
......@@ -261,7 +266,6 @@ export default {
},
refreshTable(clearMuti = true) {
console.log('??????')
// 清空多选
clearMuti && this.clearMutiSelect()
this.loading = true
......@@ -274,8 +278,7 @@ export default {
params.sortColum = this.sortColum
params.sort = this.sort === 'descending' ? 1 : 0
}
this.getListApi(params).then(res => {
console.log(res)
request(this.apiParame.apiUrl, this.apiParame.method || 'get', params).then(res => {
var data = res.data
this.data = data[this.tableParams.listName]
console.log(this.data)
......@@ -289,12 +292,12 @@ export default {
// 页码
handleSizeChange(value) {
this.page.pageSize = value
this.getListApi ? this.refreshTable(false) : this.$emit('refreshTable', this.page)
this.apiParame ? this.refreshTable(false) : this.$emit('refreshTable', this.page)
},
handleCurrentChange(value) {
this.page.pageNum = value
this.getListApi ? this.refreshTable(false) : this.$emit('refreshTable', this.page)
this.apiParame ? this.refreshTable(false) : this.$emit('refreshTable', this.page)
}
}
}
......
......@@ -14,7 +14,10 @@ const API = {
return MOCK_CONFIG_URL + '/test_config'
},
LOGIN_ACTION: BASE_URL + '/login_action',
USER_SEARCH: BASE_URL + '/usercenter/user/search',
USER_SEARCH: {
apiUrl: BASE_URL + '/usercenter/user/search'
// method: 'post'
},
ORGINIZA_SEARCH: BASE_URL + '/usercenter/organization/rootList',
ORGINIZA_CHILDREN: BASE_URL + '/usercenter/organization/children'
}
......
import HTTP from '@/utils/http'
const axiosHttp = new HTTP()
function request(url = '', method = 'GET', data = {}) {
return new Promise((resolve, reject) => {
var reqMethod = method.toLocaleLowerCase() === 'get' ? 'axiosGet' : 'axiosPost'
axiosHttp[reqMethod]({
url: url,
data: data,
success(data) {
resolve(data)
},
error(error) {
reject(error)
}
})
})
}
export default request
\ No newline at end of file
import HTTP from '@/utils/http'
import { API } from '@/config/config'
// import HTTP from '@/utils/http'
// import request from './request.js'
// import {
// API
// } from '@/config/config'
// // const aa = new HTTP()
// function getUserList(data) {
// request(API.USER_SEARCH, 'get', data)
// // return new Promise((resolve, reject) => {
// // aa.axiosGet({
// // url: API.USER_SEARCH,
// // data: {aa: 1},
// // success(data) {
// // console.log(data)
// // resolve(data)
// // },
// // error(error) {
// // // 网络请求失败
// // console.log('网络请求失败')
// // // window.location.reload()
// // }
// // })
// // })
export default class UserService extends HTTP {
getUserList () {
return new Promise((resolve, reject) => {
this.axiosGet({
url: API.USER_SEARCH,
data: {},
success(data) {
resolve(data)
},
error(error) {
// 网络请求失败
console.log('网络请求失败')
// window.location.reload()
}
})
})
}
}
// }
// export {
// getUserList
// }
\ No newline at end of file
......@@ -99,7 +99,8 @@ export default class HTTP {
axiosGet (options) {
instance({
url: options.url,
method: 'get'
method: 'get',
params: options.data
}).then((res) => {
options.success(res.data)
}).catch((err) => {
......
......@@ -45,8 +45,8 @@
</div>
<basic-table
:tableParams="tableParams"
:getListApi="getListApi"
:searchForm="searchForm"
:apiParame="apiParame"
:hasNum="false"
>
<span
......@@ -114,8 +114,11 @@
</template>
<script>
import UserService from 'services/user';
const userService = new UserService();
import {
API
} from '@/config/config'
// import { getUserList } from '@/services/user';
// const userService = new UserService();
export default {
data() {
return {
......@@ -188,7 +191,8 @@ export default {
]
}
},
getListApi: userService.getUserList,
apiParame: API.USER_SEARCH,
// getListApi: getUserList,
// 折叠菜单数据
props: {
label: 'departmentName',
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!