table/tableSelect/upload 配置抽离

This commit is contained in:
sc 2021-06-22 13:49:53 +08:00
parent 4f002e2cb4
commit 520eb35c59
7 changed files with 93 additions and 26 deletions

View File

@ -36,6 +36,7 @@
</template> </template>
<script> <script>
import config from "@/config/table";
import columnSetting from './columnSetting' import columnSetting from './columnSetting'
export default { export default {
@ -71,7 +72,7 @@
emptyText: "暂无数据", emptyText: "暂无数据",
toggleIndex: 0, toggleIndex: 0,
tableData: [], tableData: [],
pageSize: 20, pageSize: config.pageSize,
total: 0, total: 0,
currentPage: 1, currentPage: 1,
loading: false, loading: false,
@ -111,7 +112,8 @@
async getData(){ async getData(){
this.loading = true; this.loading = true;
var reqData = { var reqData = {
page: this.currentPage [config.request.page]: this.currentPage,
[config.request.pageSize]: this.pageSize
} }
Object.assign(reqData, this.tableParams) Object.assign(reqData, this.tableParams)
try { try {
@ -121,10 +123,16 @@
this.emptyText = error.statusText; this.emptyText = error.statusText;
return false; return false;
} }
this.emptyText = "暂无数据"; var response = config.parseData(res);
this.tableData = res.data; if(response.code != 200){
this.total = res.count;
this.loading = false; this.loading = false;
this.emptyText = response.msg;
}else{
this.emptyText = "暂无数据";
this.tableData = response.rows;
this.total = response.total;
this.loading = false;
}
}, },
// //
reload(){ reload(){

View File

@ -27,6 +27,8 @@
</template> </template>
<script> <script>
import config from "@/config/tableSelect";
export default { export default {
props: { props: {
modelValue: null, modelValue: null,
@ -44,15 +46,15 @@
keyword: null, keyword: null,
defaultValue: [], defaultValue: [],
tableData: [], tableData: [],
pageSize: 20, pageSize: config.pageSize,
total: 0, total: 0,
currentPage: 1, currentPage: 1,
defaultProps: { defaultProps: {
label: 'label', label: config.props.label,
value: 'value', value: config.props.value,
page: 'page', page: config.request.page,
pageSize: 'pageSize', pageSize: config.request.pageSize,
keyword: 'keyword' keyword: config.request.keyword
} }
} }
}, },
@ -92,8 +94,9 @@
[this.defaultProps.keyword]: this.keyword [this.defaultProps.keyword]: this.keyword
} }
var res = await this.apiObj.get(reqData); var res = await this.apiObj.get(reqData);
this.tableData = res.data.rows; var parseData = config.parseData(res)
this.total = res.data.total; this.tableData = parseData.rows;
this.total = parseData.total;
this.loading = false; this.loading = false;
// //
this.$nextTick(() => { this.$nextTick(() => {

View File

@ -22,7 +22,7 @@
</template> </template>
<script> <script>
import API from "@/api"; import config from "@/config/upload";
export default { export default {
props: { props: {
@ -32,7 +32,7 @@
action: { type: String, default: "" }, action: { type: String, default: "" },
apiObj: { type: Object, default: () => {} }, apiObj: { type: Object, default: () => {} },
accept: { type: String, default: ".jpg, .png, .jpeg, .gif" }, accept: { type: String, default: ".jpg, .png, .jpeg, .gif" },
maxSize: { type: Number, default: 10 }, maxSize: { type: Number, default: config.maxSize },
title: { type: String, default: "" }, title: { type: String, default: "" },
icon: { type: String, default: "el-icon-plus" }, icon: { type: String, default: "el-icon-plus" },
onSuccess: { type: Function, default: () => { return true } } onSuccess: { type: Function, default: () => { return true } }
@ -75,7 +75,7 @@
before(file){ before(file){
const maxSize = file.size / 1024 / 1024 < this.maxSize; const maxSize = file.size / 1024 / 1024 < this.maxSize;
if (!maxSize) { if (!maxSize) {
this.$message.warning('上传文件大小不能超过 10MB!'); this.$message.warning(`上传文件大小不能超过 ${this.maxSize}MB!`);
return false; return false;
} }
this.isImg(file.name) this.isImg(file.name)
@ -89,10 +89,11 @@
if(os!=undefined && os==false){ if(os!=undefined && os==false){
return false; return false;
} }
if(res.code != 200){ var response = config.parseData(res);
this.$message.warning(res.message || "上传文件未知错误") if(response.code != 200){
this.$message.warning(response.msg || "上传文件未知错误")
}else{ }else{
this.img = res.data.src; this.img = response.src;
} }
}, },
error(err){ error(err){
@ -108,7 +109,7 @@
this.img = "" this.img = ""
}, },
request(param){ request(param){
var apiObj = API.default.upload; var apiObj = config.apiObj;
if(this.apiObj){ if(this.apiObj){
apiObj = this.apiObj; apiObj = this.apiObj;
} }

View File

@ -34,7 +34,7 @@
</template> </template>
<script> <script>
import API from "@/api"; import config from "@/config/upload";
export default { export default {
props: { props: {
@ -42,7 +42,7 @@
action: { type: String, default: "" }, action: { type: String, default: "" },
apiObj: { type: Object, default: () => {} }, apiObj: { type: Object, default: () => {} },
accept: { type: String, default: ".jpg, .png, .jpeg, .gif" }, accept: { type: String, default: ".jpg, .png, .jpeg, .gif" },
maxSize: { type: Number, default: 10 }, maxSize: { type: Number, default: config.maxSize },
title: { type: String, default: "" }, title: { type: String, default: "" },
icon: { type: String, default: "el-icon-plus" } icon: { type: String, default: "el-icon-plus" }
}, },
@ -122,7 +122,7 @@
before(file){ before(file){
const maxSize = file.size / 1024 / 1024 < this.maxSize; const maxSize = file.size / 1024 / 1024 < this.maxSize;
if (!maxSize) { if (!maxSize) {
this.$message.warning('上传文件大小不能超过 10MB!'); this.$message.warning(`上传文件大小不能超过 ${this.maxSize}MB!`);
return false; return false;
} }
}, },
@ -131,7 +131,8 @@
this.fileList = fileList this.fileList = fileList
}, },
success(res, file){ success(res, file){
file.url = res.data.src var response = config.parseData(res);
file.url = response.src
}, },
progress(){ progress(){
@ -149,7 +150,7 @@
this.fileList.splice(index, 1); this.fileList.splice(index, 1);
}, },
request(param){ request(param){
var apiObj = API.default.upload; var apiObj = config.apiObj;
if(this.apiObj){ if(this.apiObj){
apiObj = this.apiObj; apiObj = this.apiObj;
} }

17
src/config/table.js Normal file
View File

@ -0,0 +1,17 @@
//数据表格配置
export default {
pageSize: 20, //表格每一页条数
parseData: function (res) { //数据分析
return {
rows: res.data, //分析行数据字段结构
total: res.count, //分析总数字段结构
msg: res.message, //分析描述字段结构
code: res.code //分析状态字段结构
}
},
request: { //请求规定字段
page: 'page', //规定当前分页字段
pageSize: 'pageSize' //规定一页条数字段
}
}

22
src/config/tableSelect.js Normal file
View File

@ -0,0 +1,22 @@
//表格选择器配置
export default {
pageSize: 20, //表格每一页条数
parseData: function (res) {
return {
rows: res.data.rows, //分析行数据字段结构
total: res.data.total, //分析总数字段结构
msg: res.message, //分析描述字段结构
code: res.code //分析状态字段结构
}
},
request: {
page: 'page', //规定当前分页字段
pageSize: 'pageSize', //规定一页条数字段
keyword: 'keyword' //规定搜索字段
},
props: {
label: 'label', //映射label显示字段
value: 'value', //映射value值字段
}
}

15
src/config/upload.js Normal file
View File

@ -0,0 +1,15 @@
import API from "@/api";
//上传配置
export default {
apiObj: API.default.upload, //上传请求API对象
maxSize: 10, //最大文件大小 默认10MB
parseData: function (res) {
return {
code: res.code, //分析状态字段结构
src: res.data.src, //分析图片远程地址结构
msg: res.message //分析描述字段结构
}
}
}