Commit 3474f96a by cwq0219

表格-接口

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