接口字段名称优化

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,5 @@
<template> <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> <template #do>
<el-button v-auth="'crontab:add'" type="primary" icon="el-icon-plus" @click="add"></el-button> <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()" <el-button v-auth="'crontab:edit'" type="success" icon="el-icon-edit" @click="edit()"

View File

@ -1,5 +1,5 @@
<template> <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> <template #do>
<el-button v-auth="'crontab:log:del'" type="danger" plain icon="el-icon-delete" <el-button v-auth="'crontab:log:del'" type="danger" plain icon="el-icon-delete"
:disabled="selection.length===0" @click="batch_del">删除</el-button> :disabled="selection.length===0" @click="batch_del">删除</el-button>
@ -7,7 +7,7 @@
@click="batch_empty">清空</el-button> @click="batch_empty">清空</el-button>
</template> </template>
<template #search> <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> :props="{label: 'crontab_name', value:'crontab_id'}" style="width: 200px;"></pi-select>
<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button> <el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
</template> </template>

View File

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

View File

@ -13,7 +13,7 @@
</el-main> </el-main>
</el-container> </el-container>
</el-aside> </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> remoteFilter>
<template #do> <template #do>
<el-button v-auth="'account:add'" type="primary" icon="el-icon-plus" @click="add"></el-button> <el-button v-auth="'account:add'" type="primary" icon="el-icon-plus" @click="add"></el-button>

View File

@ -1,5 +1,5 @@
<template> <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> <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: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" <el-button v-auth="'system_config:edit'" type="success" icon="el-icon-edit" @click="edit"

View File

@ -1,5 +1,5 @@
<template> <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> hidePagination>
<template #do> <template #do>
<el-button v-auth="'dept:add'" type="primary" icon="el-icon-plus" @click="add"></el-button> <el-button v-auth="'dept:add'" type="primary" icon="el-icon-plus" @click="add"></el-button>

View File

@ -1,5 +1,5 @@
<template> <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> <template #do>
<el-button v-auth="'dict:add'" type="primary" icon="el-icon-plus" @click="add"></el-button> <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" <el-button v-auth="'dict:edit'" type="success" icon="el-icon-edit" @click="edit"

View File

@ -1,5 +1,5 @@
<template> <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> <template #extend>
<el-select v-model="search.status" style="width: 200px;" placeholder="是否启用" clearable> <el-select v-model="search.status" style="width: 200px;" placeholder="是否启用" clearable>
<el-option label="启用" :value="1"></el-option> <el-option label="启用" :value="1"></el-option>

View File

@ -1,5 +1,5 @@
<template> <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> <template #do>
<el-button v-auth="'message:add'" type="primary" icon="el-icon-plus" @click="add"></el-button> <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" <el-button v-auth="'message:edit'" type="success" icon="el-icon-edit" @click="edit"

View File

@ -1,11 +1,11 @@
<template> <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> <template #do>
<el-button v-auth="'post:add'" type="primary" icon="el-icon-plus" @click="add"></el-button> <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" <el-button v-auth="'post:del'" type="danger" plain icon="el-icon-delete" :disabled="selection.length===0"
@click="batch_del"></el-button> @click="batch_del"></el-button>
<pi-export v-auth="'post:export'" module="post_export" :params="search" name="岗位列表导出"></pi-export> <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>
<template #search> <template #search>
<el-input v-model="search.post_name" placeholder="岗位名称" clearable style="width: 200px;"></el-input> <el-input v-model="search.post_name" placeholder="岗位名称" clearable style="width: 200px;"></el-input>

View File

@ -1,5 +1,5 @@
<template> <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> <template #do>
<el-button v-auth="'role:add'" type="primary" icon="el-icon-plus" @click="add"></el-button> <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> <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> <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> <template #do>
<el-button v-auth="'translation:add'" type="primary" icon="el-icon-plus" @click="add"></el-button> <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" <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> :disabled="selection.length===0" @click="batch_del"></el-button>
</template> </template>
<template #search> <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> :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-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> <el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>

View File

@ -3,7 +3,7 @@
<el-main> <el-main>
<el-form :model="form" :rules="rules" :disabled="mode==='show'" ref="formRef" label-width="100px"> <el-form :model="form" :rules="rules" :disabled="mode==='show'" ref="formRef" label-width="100px">
<el-form-item label="分组" prop="group"> <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'}" :params="{key: 'sys_langs_group'}"
:props="{label: 'dict_label', value: 'dict_value'}" :props="{label: 'dict_label', value: 'dict_value'}"
placeholder="请输入分组" clearable/> placeholder="请输入分组" clearable/>

View File

@ -135,7 +135,7 @@
</el-form> </el-form>
</el-tab-pane> </el-tab-pane>
<el-tab-pane label="登录日志" name="2"> <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="#" type="index" width="50"></el-table-column>
<el-table-column label="操作" prop="title"></el-table-column> <el-table-column label="操作" prop="title"></el-table-column>
<el-table-column label="状态" prop="code"> <el-table-column label="状态" prop="code">

View File

@ -1,5 +1,5 @@
<template> <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> <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: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()" <el-button v-auth="'gen_table:edit'" type="success" icon="el-icon-edit" @click="edit()"

View File

@ -1,6 +1,6 @@
<template> <template>
<el-dialog title="导入表" v-model="visible" :width="800" destroy-on-close @closed="$emit('closed')"> <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> :page-size="10" hide-do>
<template #do> <template #do>
<el-input v-model="search.table_name" placeholder="表名称" clearable style="width: 200px;" <el-input v-model="search.table_name" placeholder="表名称" clearable style="width: 200px;"