no message

This commit is contained in:
小陌 2023-06-19 22:55:32 +08:00
parent e91f1009df
commit 8f5aebb5f9
7 changed files with 240 additions and 246 deletions

View File

@ -3,7 +3,7 @@
<div class="scTable-table" :style="{'height':_table_height}"> <div class="scTable-table" :style="{'height':_table_height}">
<el-table v-bind="$attrs" :data="tableData" :row-key="rowKey" :key="toggleIndex" ref="scTable" :height="height=='auto'?null:'100%'" :size="config.size" :border="config.border" :stripe="config.stripe" :summary-method="remoteSummary?remoteSummaryMethod:summaryMethod" @sort-change="sortChange" @filter-change="filterChange"> <el-table v-bind="$attrs" :data="tableData" :row-key="rowKey" :key="toggleIndex" ref="scTable" :height="height=='auto'?null:'100%'" :size="config.size" :border="config.border" :stripe="config.stripe" :summary-method="remoteSummary?remoteSummaryMethod:summaryMethod" @sort-change="sortChange" @filter-change="filterChange">
<slot></slot> <slot></slot>
<template v-for="(item, index) in userColumn" :key="index"> <template v-for="(item, index) in column" :key="index">
<el-table-column v-if="!item.hide" :column-key="item.prop" :label="item.label" :prop="item.prop" :width="item.width" :sortable="item.sortable" :fixed="item.fixed" :filters="item.filters" :filter-method="remoteFilter||!item.filters?null:filterHandler" :show-overflow-tooltip="item.showOverflowTooltip"> <el-table-column v-if="!item.hide" :column-key="item.prop" :label="item.label" :prop="item.prop" :width="item.width" :sortable="item.sortable" :fixed="item.fixed" :filters="item.filters" :filter-method="remoteFilter||!item.filters?null:filterHandler" :show-overflow-tooltip="item.showOverflowTooltip">
<template #default="scope"> <template #default="scope">
<slot :name="item.prop" v-bind="scope"> <slot :name="item.prop" v-bind="scope">
@ -24,11 +24,11 @@
</div> </div>
<div class="scTable-do" v-if="!hideDo"> <div class="scTable-do" v-if="!hideDo">
<el-button v-if="!hideRefresh" @click="refresh" icon="el-icon-refresh" circle style="margin-left:15px"></el-button> <el-button v-if="!hideRefresh" @click="refresh" icon="el-icon-refresh" circle style="margin-left:15px"></el-button>
<el-popover v-if="column" placement="top" title="列设置" :width="500" trigger="click" :hide-after="0" @show="customColumnShow=true" @after-leave="customColumnShow=false"> <el-popover v-if="columnSetting" placement="top" title="列设置" :width="500" trigger="click" :hide-after="0" @show="customColumnShow=true" @after-leave="customColumnShow=false">
<template #reference> <template #reference>
<el-button icon="el-icon-set-up" circle style="margin-left:15px"></el-button> <el-button icon="el-icon-set-up" circle style="margin-left:15px"></el-button>
</template> </template>
<columnSetting v-if="customColumnShow" ref="columnSetting" @userChange="columnSettingChange" @save="columnSettingSave" @back="columnSettingBack" :column="userColumn"></columnSetting> <columnSetting v-if="customColumnShow" ref="columnSetting" @userChange="columnSettingChange" @save="columnSettingSave" @back="columnSettingBack" :column="column"></columnSetting>
</el-popover> </el-popover>
<el-popover v-if="!hideSetting" placement="top" title="表格设置" :width="400" trigger="click" :hide-after="0"> <el-popover v-if="!hideSetting" placement="top" title="表格设置" :width="400" trigger="click" :hide-after="0">
<template #reference> <template #reference>
@ -63,7 +63,8 @@
columnSetting columnSetting
}, },
props: { props: {
tablename: { type: String, default: "" }, name: { type: String, default: "" },
tableColumn: { type: Object, default: () => {} },
apiObj: { type: Object, default: () => {} }, apiObj: { type: Object, default: () => {} },
params: { type: Object, default: () => ({}) }, params: { type: Object, default: () => ({}) },
data: { type: Object, default: () => {} }, data: { type: Object, default: () => {} },
@ -75,7 +76,6 @@
pageSizes: { type: Array, default: config.pageSizes }, pageSizes: { type: Array, default: config.pageSizes },
rowKey: { type: String, default: "" }, rowKey: { type: String, default: "" },
summaryMethod: { type: Function, default: null }, summaryMethod: { type: Function, default: null },
column: { type: Object, default: () => {} },
remoteSort: { type: Boolean, default: false }, remoteSort: { type: Boolean, default: false },
remoteFilter: { type: Boolean, default: false }, remoteFilter: { type: Boolean, default: false },
remoteSummary: { type: Boolean, default: false }, remoteSummary: { type: Boolean, default: false },
@ -86,6 +86,7 @@
paginationLayout: { type: String, default: config.paginationLayout }, paginationLayout: { type: String, default: config.paginationLayout },
}, },
watch: { watch: {
//props //props
data(){ data(){
this.tableData = this.data; this.tableData = this.data;
@ -95,8 +96,8 @@
this.tableParams = this.params; this.tableParams = this.params;
this.refresh(); this.refresh();
}, },
column(){ tableColumn(){
this.userColumn=this.column; this.column = this.tableColumn;
} }
}, },
computed: { computed: {
@ -111,6 +112,7 @@
return { return {
scPageSize: this.pageSize, scPageSize: this.pageSize,
isActivat: true, isActivat: true,
api: '',
emptyText: "暂无数据", emptyText: "暂无数据",
toggleIndex: 0, toggleIndex: 0,
tableData: [], tableData: [],
@ -121,7 +123,8 @@
loading: false, loading: false,
tableHeight:'100%', tableHeight:'100%',
tableParams: this.params, tableParams: this.params,
userColumn: [], column: [],
columnSetting: false,
customColumnShow: false, customColumnShow: false,
summary: {}, summary: {},
config: { config: {
@ -132,12 +135,23 @@
} }
}, },
mounted() { mounted() {
// //
if(this.tablename){ if(this.name) {
this.getCustomColumn() this.$http.get(config.configUrl, { name: this.name }, { cache:0 }).then((res) => {
if (res.code == 200) {
Object.assign(this.$data, res.data);
if (typeof res.data.api !== 'undefined' && res.data.api) {
this.api = res.data.api;
this.getData();
}
}
});
}else{ }else{
this.userColumn = this.column this.column = this.tableColumn
} }
// //
if(this.apiObj){ if(this.apiObj){
this.getData(); this.getData();
@ -155,11 +169,6 @@
this.isActivat = false; this.isActivat = false;
}, },
methods: { methods: {
//
async getCustomColumn(){
const userColumn = await config.columnSettingGet(this.tablename, this.column)
this.userColumn = userColumn
},
// //
async getData(){ async getData(){
this.loading = true; this.loading = true;
@ -176,7 +185,9 @@
Object.assign(reqData, this.tableParams) Object.assign(reqData, this.tableParams)
try { try {
var res = await this.apiObj(reqData);
var res = this.api? await this.$http.get(this.api, reqData):await this.apiObj(reqData);
}catch(error){ }catch(error){
this.loading = false; this.loading = false;
this.emptyText = error.statusText; this.emptyText = error.statusText;
@ -237,15 +248,15 @@
this.getData() this.getData()
}, },
// //
columnSettingChange(userColumn){ columnSettingChange(column){
this.userColumn = userColumn; this.column = column;
this.toggleIndex += 1; this.toggleIndex += 1;
}, },
// //
async columnSettingSave(userColumn){ async columnSettingSave(column){
this.$refs.columnSetting.isSave = true this.$refs.columnSetting.isSave = true
try { try {
await config.columnSettingSave(this.tablename, userColumn) await config.columnSettingSave(this.name, column)
}catch(error){ }catch(error){
this.$message.error('保存失败') this.$message.error('保存失败')
this.$refs.columnSetting.isSave = false this.$refs.columnSetting.isSave = false
@ -257,9 +268,9 @@
async columnSettingBack(){ async columnSettingBack(){
this.$refs.columnSetting.isSave = true this.$refs.columnSetting.isSave = true
try { try {
const column = await config.columnSettingReset(this.tablename, this.column) const column = await config.columnSettingReset(this.name, this.column)
this.userColumn = column this.column = column
this.$refs.columnSetting.usercolumn = JSON.parse(JSON.stringify(this.userColumn||[])) this.$refs.columnSetting.column = JSON.parse(JSON.stringify(this.column||[]))
}catch(error){ }catch(error){
this.$message.error('重置失败') this.$message.error('重置失败')
this.$refs.columnSetting.isSave = false this.$refs.columnSetting.isSave = false
@ -271,7 +282,7 @@
if(!this.remoteSort){ if(!this.remoteSort){
return false return false
} }
if(obj.column && obj.prop){ if(obj.tableColumn && obj.prop){
this.prop = obj.prop this.prop = obj.prop
this.order = obj.order this.order = obj.order
}else{ }else{

View File

@ -1,6 +1,5 @@
//数据表格配置 //数据表格配置
import tool from '@/utils/tool' import tool from '@/utils/tool'
import http from "@/utils/request"
export default { export default {
successCode: 200, //请求完成代码 successCode: 200, //请求完成代码
pageSize: 20, //表格每一页条数 pageSize: 20, //表格每一页条数
@ -22,6 +21,7 @@ export default {
prop: 'prop', //规定排序字段名字段 prop: 'prop', //规定排序字段名字段
order: 'order' //规定排序规格字段 order: 'order' //规定排序规格字段
}, },
configUrl: 'system/table/get',
/** /**
* 自定义列保存处理 * 自定义列保存处理
* @tablename scTable组件的props->tablename * @tablename scTable组件的props->tablename
@ -36,25 +36,6 @@ export default {
}, 1000) }, 1000)
}) })
}, },
/**
* 获取自定义列
* @tablename scTable组件的props->tablename
* @column 组件接受到的props->column
*/
columnSettingGet: function(tablename, column) {
return new Promise((resolve) => {
//这里为了演示使用了session和setTimeout演示开发时应用数据请求
// const userColumn = tool.session.get(tablename)
http.post('system/table/get', { name: tablename }).then((res) => {
if (res.code == 200) {
resolve(res.data.column)
return false;
}
resolve(column)
});
})
},
/** /**
* 重置自定义列 * 重置自定义列
* @tablename scTable组件的props->tablename * @tablename scTable组件的props->tablename

View File

@ -1,210 +1,209 @@
import axios from 'axios'; import axios from 'axios';
import { ElNotification, ElMessageBox } from 'element-plus'; import {
ElNotification,
ElMessageBox
} from 'element-plus';
import sysConfig from "@/config"; import sysConfig from "@/config";
import tool from '@/utils/tool'; import tool from '@/utils/tool';
import router from '@/router'; import router from '@/router';
axios.defaults.baseURL = sysConfig.API_URL axios.defaults.baseURL = sysConfig.API_URL
axios.defaults.timeout = sysConfig.TIMEOUT axios.defaults.timeout = sysConfig.TIMEOUT
// HTTP request 拦截器 // HTTP request 拦截器
axios.interceptors.request.use( axios.interceptors.request.use(
(config) => { (config) => {
let token = tool.cookie.get("token"); let token = tool.cookie.get("token");
if(token){ if (token) {
config.headers[sysConfig.TOKEN_NAME] = sysConfig.TOKEN_PREFIX + token config.headers[sysConfig.TOKEN_NAME] = sysConfig.TOKEN_PREFIX + token
} }
if(!sysConfig.REQUEST_CACHE && config.method == 'get'){ if (!sysConfig.REQUEST_CACHE && config.method == 'get') {
config.params = config.params || {}; config.params = config.params || {};
config.params['_'] = new Date().getTime(); config.params['_'] = new Date().getTime();
} }
Object.assign(config.headers, sysConfig.HEADERS) Object.assign(config.headers, sysConfig.HEADERS)
return config; return config;
}, }, (error) => {
(error) => { return Promise.reject(error);
return Promise.reject(error); });
}
);
//FIX 多个API同时401时疯狂弹窗BUG //FIX 多个API同时401时疯狂弹窗BUG
let MessageBox_401_show = false let MessageBox_401_show = false
// HTTP response 拦截器 // HTTP response 拦截器
axios.interceptors.response.use( axios.interceptors.response.use(
(response) => { (response) => {
return response; return response;
}, }, (error) => {
(error) => { if (error.response) {
if (error.response) { if (error.response.status == 404) {
if (error.response.status == 404) { ElNotification.error({
ElNotification.error({ title: '请求错误',
title: '请求错误', message: "Status:404正在请求不存在的服务器记录"
message: "Status:404正在请求不存在的服务器记录" });
}); } else if (error.response.status == 500) {
} else if (error.response.status == 500) { ElNotification.error({
ElNotification.error({ title: '请求错误',
title: '请求错误', message: error.response.data.message || "Status:500服务器发生错误"
message: error.response.data.message || "Status:500服务器发生错误" });
}); } else if (error.response.status == 401) {
} else if (error.response.status == 401) { if (!MessageBox_401_show) {
if(!MessageBox_401_show){ MessageBox_401_show = true
MessageBox_401_show = true ElMessageBox.confirm('当前用户已被登出或无权限访问当前资源,请尝试重新登录后再操作。', '无权限访问', {
ElMessageBox.confirm('当前用户已被登出或无权限访问当前资源,请尝试重新登录后再操作。', '无权限访问', { type: 'error',
type: 'error', closeOnClickModal: false,
closeOnClickModal: false, center: true,
center: true, confirmButtonText: '重新登录',
confirmButtonText: '重新登录', beforeClose: (action, instance, done) => {
beforeClose: (action, instance, done) => { MessageBox_401_show = false
MessageBox_401_show = false done()
done() }
} }).then(() => {
}).then(() => { router.replace({
router.replace({path: '/login'}); path: '/login'
}).catch(() => {}) });
} }).catch(() => {})
} else { }
ElNotification.error({ } else {
title: '请求错误', ElNotification.error({
message: error.message || `Status:${error.response.status},未知错误!` title: '请求错误',
}); message: error.message || `Status:${error.response.status},未知错误!`
} });
} else { }
ElNotification.error({ } else {
title: '请求错误', ElNotification.error({
message: "请求服务器无响应!" title: '请求错误',
}); message: "请求服务器无响应!"
} });
}
return Promise.reject(error.response); return Promise.reject(error.response);
} });
);
var http = { var http = {
/** get
/** get * @param {string} url 接口地址
* @param {string} url 接口地址 * @param {object} params 请求参数
* @param {object} params 请求参数 * @param {object} config 参数
* @param {object} config 参数 */
*/ get: function(url, params = {}, config = {}) {
get: function(url, params={}, config={}) { return new Promise((resolve, reject) => {
return new Promise((resolve, reject) => { // 缓存存在, 优先使用缓存
axios({ const cacheKey = '';
method: 'get', if (typeof config.cache !== 'undefined' && !isNaN(config.cache) && config.cache > 0) {
url: url, let cacheKey = tool.crypto.MD5(url);
params: params, const cachedData = tool.data.get(cacheKey);
...config if (cachedData) {
}).then((response) => { return resolve(cachedData);
resolve(response.data); }
}).catch((error) => { }
reject(error); axios({
}) method: 'get',
}) url: url,
}, params: params,
...config
/** post }).then((response) => {
* @param {string} url 接口地址 if (cacheKey) {
* @param {object} data 请求参数 tool.data.set(cacheKey, response.data, config.cache);
* @param {object} config 参数 }
*/ resolve(response.data);
post: function(url, data={}, config={}) { }).catch((error) => {
return new Promise((resolve, reject) => { reject(error);
axios({ })
method: 'post', })
url: url, },
data: data, /** post
...config * @param {string} url 接口地址
}).then((response) => { * @param {object} data 请求参数
resolve(response.data); * @param {object} config 参数
}).catch((error) => { */
reject(error); post: function(url, data = {}, config = {}) {
}) return new Promise((resolve, reject) => {
}) axios({
}, method: 'post',
url: url,
/** put data: data,
* @param {string} url 接口地址 ...config
* @param {object} data 请求参数 }).then((response) => {
* @param {object} config 参数 resolve(response.data);
*/ }).catch((error) => {
put: function(url, data={}, config={}) { reject(error);
return new Promise((resolve, reject) => { })
axios({ })
method: 'put', },
url: url, /** put
data: data, * @param {string} url 接口地址
...config * @param {object} data 请求参数
}).then((response) => { * @param {object} config 参数
resolve(response.data); */
}).catch((error) => { put: function(url, data = {}, config = {}) {
reject(error); return new Promise((resolve, reject) => {
}) axios({
}) method: 'put',
}, url: url,
data: data,
/** patch ...config
* @param {string} url 接口地址 }).then((response) => {
* @param {object} data 请求参数 resolve(response.data);
* @param {object} config 参数 }).catch((error) => {
*/ reject(error);
patch: function(url, data={}, config={}) { })
return new Promise((resolve, reject) => { })
axios({ },
method: 'patch', /** patch
url: url, * @param {string} url 接口地址
data: data, * @param {object} data 请求参数
...config * @param {object} config 参数
}).then((response) => { */
resolve(response.data); patch: function(url, data = {}, config = {}) {
}).catch((error) => { return new Promise((resolve, reject) => {
reject(error); axios({
}) method: 'patch',
}) url: url,
}, data: data,
...config
/** delete }).then((response) => {
* @param {string} url 接口地址 resolve(response.data);
* @param {object} data 请求参数 }).catch((error) => {
* @param {object} config 参数 reject(error);
*/ })
delete: function(url, data={}, config={}) { })
return new Promise((resolve, reject) => { },
axios({ /** delete
method: 'delete', * @param {string} url 接口地址
url: url, * @param {object} data 请求参数
data: data, * @param {object} config 参数
...config */
}).then((response) => { delete: function(url, data = {}, config = {}) {
resolve(response.data); return new Promise((resolve, reject) => {
}).catch((error) => { axios({
reject(error); method: 'delete',
}) url: url,
}) data: data,
}, ...config
}).then((response) => {
/** jsonp resolve(response.data);
* @param {string} url 接口地址 }).catch((error) => {
* @param {string} name JSONP回调函数名称 reject(error);
*/ })
jsonp: function(url, name='jsonp'){ })
return new Promise((resolve) => { },
var script = document.createElement('script') /** jsonp
var _id = `jsonp${Math.ceil(Math.random() * 1000000)}` * @param {string} url 接口地址
script.id = _id * @param {string} name JSONP回调函数名称
script.type = 'text/javascript' */
script.src = url jsonp: function(url, name = 'jsonp') {
window[name] =(response) => { return new Promise((resolve) => {
resolve(response) var script = document.createElement('script')
document.getElementsByTagName('head')[0].removeChild(script) var _id = `jsonp${Math.ceil(Math.random() * 1000000)}`
try { script.id = _id
delete window[name]; script.type = 'text/javascript'
}catch(e){ script.src = url
window[name] = undefined; window[name] = (response) => {
} resolve(response)
} document.getElementsByTagName('head')[0].removeChild(script)
document.getElementsByTagName('head')[0].appendChild(script) try {
}) delete window[name];
} } catch (e) {
window[name] = undefined;
}
}
document.getElementsByTagName('head')[0].appendChild(script)
})
}
} }
export default http; export default http;

View File

@ -46,7 +46,7 @@
import save from './save' import save from './save'
export default { export default {
name: "settingMenu", name: "systemmenu",
components: { components: {
save save
}, },

View File

@ -46,7 +46,6 @@
</el-form-item> </el-form-item>
<el-form-item label="颜色" prop="color"> <el-form-item label="颜色" prop="color">
<el-color-picker v-model="form.meta.color" :predefine="predefineColors"></el-color-picker> <el-color-picker v-model="form.meta.color" :predefine="predefineColors"></el-color-picker>
</el-form-item> </el-form-item>
<el-form-item label="是否隐藏" prop="meta.hidden"> <el-form-item label="是否隐藏" prop="meta.hidden">
<el-checkbox v-model="form.meta.hidden">隐藏菜单</el-checkbox> <el-checkbox v-model="form.meta.hidden">隐藏菜单</el-checkbox>
@ -56,6 +55,9 @@
<el-form-item label="整页路由" prop="fullpage"> <el-form-item label="整页路由" prop="fullpage">
<el-switch v-model="form.meta.fullpage" /> <el-switch v-model="form.meta.fullpage" />
</el-form-item> </el-form-item>
<el-form-item label="表单名称" prop="fullpage">
<el-input v-model="form.meta.tablename" clearable placeholder="表单名称,读取配置及表头"></el-input>
</el-form-item>
<el-form-item label="标签" prop="tag"> <el-form-item label="标签" prop="tag">
<el-input v-model="form.meta.tag" clearable placeholder=""></el-input> <el-input v-model="form.meta.tag" clearable placeholder=""></el-input>
</el-form-item> </el-form-item>

View File

@ -37,7 +37,7 @@
<script> <script>
export default { export default {
name: 'system', name: 'setting',
data() { data() {
return { return {
info: {}, info: {},

View File

@ -6,7 +6,7 @@
</div> </div>
</el-header> </el-header>
<el-main class="nopadding"> <el-main class="nopadding">
<scTable ref="table" tablename="fdsafafa" :apiObj="apiObj" row-key="id" @selection-change="selectionChange" stripe> <scTable ref="table" :name="tablename" row-key="id" @selection-change="selectionChange" stripe>
<el-table-column type="selection" width="50"></el-table-column> <el-table-column type="selection" width="50"></el-table-column>
</scTable> </scTable>
</el-main> </el-main>
@ -28,7 +28,8 @@
save: false save: false
}, },
apiObj: this.$api.system.table.list, apiObj: this.$api.system.table.list,
selection: [] selection: [],
tablename: this.$route.meta.tablename || '',
} }
}, },
mounted() { mounted() {