接口字段名称优化

This commit is contained in:
zhang zhuo 2025-12-26 09:26:15 +08:00
parent aad014e54f
commit cf07ee418c
26 changed files with 56 additions and 58 deletions

View File

@ -39,7 +39,7 @@ const emit = defineEmits(["success", "closed"])
const props = defineProps({
title: {type: String, default: '请选择'},
apiObj: {
api: {
type: Function, default: () => {
}
},
@ -89,7 +89,7 @@ async function getData() {
[config.request.pageSize]: pageSize.value,
}
Object.assign(reqData, props.params, formData.value)
const res = await props.apiObj(reqData)
const res = await props.api(reqData)
tableData.value = res.data
total.value = res.count
initCheck()

View File

@ -9,7 +9,7 @@ import tools from "@/utils/tools"
const {proxy} = getCurrentInstance()
const props = defineProps({
apiObj: {
api: {
type: Object, default: () => {
}
},
@ -25,12 +25,12 @@ let loading = ref(false)
async function download() {
const data = {module: props.module, name: props.name, params: props.params}
let apiObj = props.apiObj
if (!apiObj) {
apiObj = api.tools.file.export
let api = props.api
if (!api) {
api = api.tools.file.export
}
loading.value = true
const [res, err] = await tools.go(apiObj(data))
const [res, err] = await tools.go(api(data))
loading.value = false
if (err) {
proxy.$message.error(res.msg)

View File

@ -54,7 +54,7 @@ import {getCurrentInstance, ref} from "vue"
const emit = defineEmits(["success"])
const uploaderRef = ref(null)
const props = defineProps({
apiObj: {type: Function, required: true},
api: {type: Function, required: true},
data: {
type: Object, default: () => {
}
@ -118,7 +118,7 @@ function request(param) {
for (const key in param.data) {
data.append(key, param.data[key]);
}
props.apiObj.post(data, {
props.api.post(data, {
onUploadProgress: e => {
const complete = parseInt(((e.loaded / e.total) * 100) | 0, 10)
param.onProgress({percent: complete})

View File

@ -15,7 +15,7 @@ const emit = defineEmits(['update:modelValue', 'change'])
const props = defineProps({
modelValue: null,
apiObj: {
api: {
type: Function, default: () => {
}
},
@ -63,7 +63,7 @@ onMounted(() => {
async function getData() {
loading.value = true;
const res = await props.apiObj(props.params);
const res = await props.api(props.params);
tableData.value = res.data;
loading.value = false;
}

View File

@ -117,7 +117,7 @@ const hasDoSlot = computed(() => !!slots.do)
const props = defineProps({
tableName: {type: String, default: ""},
apiObj: {
api: {
type: Function, default: () => {
}
},
@ -179,7 +179,7 @@ watch(() => props.data, () => {
total.value = tableData.value.length;
})
watch(() => props.apiObj, () => {
watch(() => props.api, () => {
tableParams.value = props.params;
refresh();
})
@ -200,7 +200,7 @@ onMounted(() => {
userColumn = props.column
}
//
if (props.apiObj) {
if (props.api) {
getData()
} else if (data.value) {
tableData.value = data.value
@ -253,7 +253,7 @@ async function getData() {
}
Object.assign(reqData, tableParams.value)
try {
var res = await props.apiObj(reqData)
var res = await props.api(reqData)
} catch (error) {
loading.value = false;
emptyText.value = error.statusText;

View File

@ -35,7 +35,7 @@ const emit = defineEmits(['update:modelValue', 'change'])
const props = defineProps({
modelValue: null,
apiObj: {
api: {
type: Function, default: () => {
}
},
@ -109,7 +109,7 @@ async function getData() {
[defaultProps.value.keyword]: keyword.value
}
Object.assign(reqData, props.params, formData.value)
var res = await props.apiObj(reqData);
var res = await props.api(reqData);
var parseData = config.parseData(res)
tableData.value = parseData.rows;
total.value = parseData.total;

View File

@ -36,11 +36,11 @@ const props = defineProps({
modelValue: { type: [String, Array], default: "" },
tip: { type: String, default: "" },
action: { type: String, default: "" },
apiObj: { type: Function, default: () => {} },
api: { type: Function, default: () => {} },
name: { type: String, default: config.filename },
data: { type: Object, default: () => {} },
accept: { type: String, default: "" },
maxSize: { type: Number, default: config.maxSizeFile },
maxSize: { type: Number, default: config.maxSiz },
limit: { type: Number, default: 0 },
autoUpload: { type: Boolean, default: true },
showFileList: { type: Boolean, default: true },
@ -158,16 +158,16 @@ function handlePreview(uploadFile){
}
function request(param){
var apiObj = config.apiObjFile;
if(props.apiObj){
apiObj = props.apiObj;
var api = config.api;
if(props.api){
api = props.api;
}
const data = new FormData();
data.append(param.filename, param.file);
for (const key in param.data) {
data.append(key, param.data[key]);
}
apiObj(data, {
api(data, {
onUploadProgress: e => {
const complete = parseInt(((e.loaded / e.total) * 100) | 0, 10)
param.onProgress({percent: complete})

View File

@ -71,11 +71,11 @@ const props = defineProps({
title: { type: String, default: "" },
icon: { type: String, default: "el-icon-plus" },
action: { type: String, default: "" },
apiObj: { type: Object, default: () => {} },
api: { type: Object, default: () => {} },
name: { type: String, default: config.filename },
data: { type: Object, default: () => {} },
accept: { type: String, default: "image/gif, image/jpeg, image/png" },
maxSize: { type: Number, default: config.maxSizeFile },
maxSize: { type: Number, default: config.maxSiz },
limit: { type: Number, default: 1 },
autoUpload: { type: Boolean, default: true },
showFileList: { type: Boolean, default: false },
@ -226,16 +226,16 @@ function error(err){
}
function request(param){
var apiObj = config.apiObj;
if(props.apiObj){
apiObj = props.apiObj;
var api = config.api;
if(props.api){
api = props.api;
}
const data = new FormData();
data.append(param.filename, param.file);
for (const key in param.data) {
data.append(key, param.data[key]);
}
apiObj(data, {
api(data, {
onUploadProgress: e => {
const complete = parseInt(((e.loaded / e.total) * 100) | 0, 10)
param.onProgress({percent: complete})

View File

@ -58,11 +58,11 @@ const props = defineProps({
modelValue: { type: [String, Array], default: "" },
tip: { type: String, default: "" },
action: { type: String, default: "" },
apiObj: { type: Object, default: () => {} },
api: { type: Object, default: () => {} },
name: { type: String, default: config.filename },
data: { type: Object, default: () => {} },
accept: { type: String, default: "image/gif, image/jpeg, image/png" },
maxSize: { type: Number, default: config.maxSizeFile },
maxSize: { type: Number, default: config.maxSiz },
limit: { type: Number, default: 0 },
autoUpload: { type: Boolean, default: true },
showFileList: { type: Boolean, default: true },
@ -212,16 +212,16 @@ function handlePreview(uploadFile){
}
function request(param){
var apiObj = config.apiObj;
if(props.apiObj){
apiObj = props.apiObj;
var api = config.api;
if(props.api){
api = props.api;
}
const data = new FormData();
data.append(param.filename, param.file);
for (const key in param.data) {
data.append(key, param.data[key]);
}
apiObj(data, {
api(data, {
onUploadProgress: e => {
const complete = parseInt(((e.loaded / e.total) * 100) | 0, 10)
param.onProgress({percent: complete})

View File

@ -3,7 +3,7 @@ import API from "@/api";
//上传配置
export default {
apiObj: API.system.upload, //上传请求API对象
api: API.system.upload, //上传请求API对象
filename: "file", //form请求时文件的key
successCode: 0, //请求完成代码
maxSize: 10, //最大文件大小 默认10MB
@ -12,7 +12,5 @@ export default {
fileName: res.fileName,
src: res.filePath,
}
},
apiObjFile: API.system.upload, //附件上传请求API对象
maxSizeFile: 10 //最大文件大小 默认10MB
}
}

View File

@ -1,5 +1,5 @@
<template>
<pi-table ref="tableRef" :apiObj="api.system.crontab.list" @selection-change="selectionChange">
<pi-table ref="tableRef" :api="api.system.crontab.list" @selection-change="selectionChange">
<template #do>
<el-button v-auth="'crontab:add'" type="primary" icon="el-icon-plus" @click="add"></el-button>
<el-button v-auth="'crontab:edit'" type="success" icon="el-icon-edit" @click="edit()"

View File

@ -1,5 +1,5 @@
<template>
<pi-table ref="tableRef" :apiObj="api.system.crontab_log.list" :params="search" @selection-change="selectionChange">
<pi-table ref="tableRef" :api="api.system.crontab_log.list" :params="search" @selection-change="selectionChange">
<template #do>
<el-button v-auth="'crontab:log:del'" type="danger" plain icon="el-icon-delete"
:disabled="selection.length===0" @click="batch_del">删除</el-button>
@ -7,7 +7,7 @@
@click="batch_empty">清空</el-button>
</template>
<template #search>
<pi-select v-model="search.crontab_id" :api-obj="api.system.crontab.option" placeholder="任务名称" clearable
<pi-select v-model="search.crontab_id" :api="api.system.crontab.option" placeholder="任务名称" clearable
:props="{label: 'crontab_name', value:'crontab_id'}" style="width: 200px;"></pi-select>
<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
</template>

View File

@ -1,5 +1,5 @@
<template>
<pi-table ref="tableRef" :apiObj="api.system.online.list">
<pi-table ref="tableRef" :api="api.system.online.list">
<template #do>
<el-input v-model="search.username" placeholder="用户名" clearable style="width: 200px;" @keyup.enter="upsearch"></el-input>
<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>

View File

@ -13,7 +13,7 @@
</el-main>
</el-container>
</el-aside>
<pi-table ref="tableRef" :apiObj="api.system.account.list" @selection-change="selectionChange" stripe remoteSort
<pi-table ref="tableRef" :api="api.system.account.list" @selection-change="selectionChange" stripe remoteSort
remoteFilter>
<template #do>
<el-button v-auth="'account:add'" type="primary" icon="el-icon-plus" @click="add"></el-button>

View File

@ -1,5 +1,5 @@
<template>
<pi-table ref="tableRef" :apiObj="api.system.config.list" @selection-change="selectionChange">
<pi-table ref="tableRef" :api="api.system.config.list" @selection-change="selectionChange">
<template #do>
<el-button v-auth="'system_config:add'" type="primary" icon="el-icon-plus" @click="add"></el-button>
<el-button v-auth="'system_config:edit'" type="success" icon="el-icon-edit" @click="edit"

View File

@ -1,5 +1,5 @@
<template>
<pi-table ref="tableRef" :apiObj="api.system.dept.list" row-key="dept_id" @selection-change="selectionChange"
<pi-table ref="tableRef" :api="api.system.dept.list" row-key="dept_id" @selection-change="selectionChange"
hidePagination>
<template #do>
<el-button v-auth="'dept:add'" type="primary" icon="el-icon-plus" @click="add"></el-button>

View File

@ -1,5 +1,5 @@
<template>
<pi-table ref="tableRef" :apiObj="api.system.dict.list" @selection-change="selectionChange">
<pi-table ref="tableRef" :api="api.system.dict.list" @selection-change="selectionChange">
<template #do>
<el-button v-auth="'dict:add'" type="primary" icon="el-icon-plus" @click="add"></el-button>
<el-button v-auth="'dict:edit'" type="success" icon="el-icon-edit" @click="edit"

View File

@ -1,5 +1,5 @@
<template>
<pi-table ref="tableRef" :params="search" :apiObj="api.system.dict_data.list" @selection-change="selectionChange">
<pi-table ref="tableRef" :params="search" :api="api.system.dict_data.list" @selection-change="selectionChange">
<template #extend>
<el-select v-model="search.status" style="width: 200px;" placeholder="是否启用" clearable>
<el-option label="启用" :value="1"></el-option>

View File

@ -1,5 +1,5 @@
<template>
<pi-table ref="tableRef" :apiObj="api.system.message.list" @selection-change="selectionChange">
<pi-table ref="tableRef" :api="api.system.message.list" @selection-change="selectionChange">
<template #do>
<el-button v-auth="'message:add'" type="primary" icon="el-icon-plus" @click="add"></el-button>
<el-button v-auth="'message:edit'" type="success" icon="el-icon-edit" @click="edit"

View File

@ -1,11 +1,11 @@
<template>
<pi-table ref="tableRef" :apiObj="api.system.post.list" @selection-change="selectionChange">
<pi-table ref="tableRef" :api="api.system.post.list" @selection-change="selectionChange">
<template #do>
<el-button v-auth="'post:add'" type="primary" icon="el-icon-plus" @click="add"></el-button>
<el-button v-auth="'post:del'" type="danger" plain icon="el-icon-delete" :disabled="selection.length===0"
@click="batch_del"></el-button>
<pi-export v-auth="'post:export'" module="post_export" :params="search" name="岗位列表导出"></pi-export>
<pi-import v-auth="'post:import'" :api-obj="api.system.post.import"></pi-import>
<pi-import v-auth="'post:import'" :api="api.system.post.import"></pi-import>
</template>
<template #search>
<el-input v-model="search.post_name" placeholder="岗位名称" clearable style="width: 200px;"></el-input>

View File

@ -1,5 +1,5 @@
<template>
<pi-table ref="tableRef" :apiObj="api.system.role.list" @selection-change="selectionChange" stripe>
<pi-table ref="tableRef" :api="api.system.role.list" @selection-change="selectionChange" stripe>
<template #do>
<el-button v-auth="'role:add'" type="primary" icon="el-icon-plus" @click="add"></el-button>
<el-button v-auth="'role:del'" type="danger" plain icon="el-icon-delete" :disabled="selection.length==0" @click="batch_del"></el-button>

View File

@ -1,5 +1,5 @@
<template>
<pi-table ref="tableRef" :apiObj="api.system.translation.list" @selection-change="selectionChange">
<pi-table ref="tableRef" :api="api.system.translation.list" @selection-change="selectionChange">
<template #do>
<el-button v-auth="'translation:add'" type="primary" icon="el-icon-plus" @click="add"></el-button>
<el-button v-auth="'translation:edit'" type="success" icon="el-icon-edit" @click="edit"
@ -8,7 +8,7 @@
:disabled="selection.length===0" @click="batch_del"></el-button>
</template>
<template #search>
<pi-select v-model="search.group" :api-obj="api.system.dict_data.option" :params="{key: 'sys_langs_group'}"
<pi-select v-model="search.group" :api="api.system.dict_data.option" :params="{key: 'sys_langs_group'}"
:props="{label: 'dict_label', value: 'dict_value'}" style="width: 200px;"></pi-select>
<el-input v-model="search.translation_key" placeholder="key" clearable style="width: 200px;"></el-input>
<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>

View File

@ -3,7 +3,7 @@
<el-main>
<el-form :model="form" :rules="rules" :disabled="mode==='show'" ref="formRef" label-width="100px">
<el-form-item label="分组" prop="group">
<pi-select v-model="form.group" :api-obj="api.system.dict_data.option"
<pi-select v-model="form.group" :api="api.system.dict_data.option"
:params="{key: 'sys_langs_group'}"
:props="{label: 'dict_label', value: 'dict_value'}"
placeholder="请输入分组" clearable/>

View File

@ -135,7 +135,7 @@
</el-form>
</el-tab-pane>
<el-tab-pane label="登录日志" name="2">
<pi-table :apiObj="api.auth.loginLog" stripe hide-act :page-size="10">
<pi-table :api="api.auth.loginLog" stripe hide-act :page-size="10">
<el-table-column label="#" type="index" width="50"></el-table-column>
<el-table-column label="操作" prop="title"></el-table-column>
<el-table-column label="状态" prop="code">

View File

@ -1,5 +1,5 @@
<template>
<pi-table ref="tableRef" :apiObj="api.tools.gen_table.list" @selection-change="selectionChange">
<pi-table ref="tableRef" :api="api.tools.gen_table.list" @selection-change="selectionChange">
<template #do>
<el-button v-auth="'gen_table:add'" type="primary" icon="el-icon-plus" @click="add"></el-button>
<el-button v-auth="'gen_table:edit'" type="success" icon="el-icon-edit" @click="edit()"

View File

@ -1,6 +1,6 @@
<template>
<el-dialog title="导入表" v-model="visible" :width="800" destroy-on-close @closed="$emit('closed')">
<pi-table ref="tableRef" :api-obj="api.tools.gen_table.select" @selection-change="selectionChange"
<pi-table ref="tableRef" :api="api.tools.gen_table.select" @selection-change="selectionChange"
:page-size="10" hide-do>
<template #do>
<el-input v-model="search.table_name" placeholder="表名称" clearable style="width: 200px;"