diff --git a/src/components/scTable/index.vue b/src/components/scTable/index.vue
index 58d35a0..b5badc2 100644
--- a/src/components/scTable/index.vue
+++ b/src/components/scTable/index.vue
@@ -3,7 +3,7 @@
-
+
@@ -24,11 +24,11 @@
-
+
-
+
@@ -63,7 +63,8 @@
columnSetting
},
props: {
- tablename: { type: String, default: "" },
+ name: { type: String, default: "" },
+ tableColumn: { type: Object, default: () => {} },
apiObj: { type: Object, default: () => {} },
params: { type: Object, default: () => ({}) },
data: { type: Object, default: () => {} },
@@ -75,7 +76,6 @@
pageSizes: { type: Array, default: config.pageSizes },
rowKey: { type: String, default: "" },
summaryMethod: { type: Function, default: null },
- column: { type: Object, default: () => {} },
remoteSort: { type: Boolean, default: false },
remoteFilter: { type: Boolean, default: false },
remoteSummary: { type: Boolean, default: false },
@@ -86,6 +86,7 @@
paginationLayout: { type: String, default: config.paginationLayout },
},
watch: {
+
//监听从props里拿到值了
data(){
this.tableData = this.data;
@@ -95,8 +96,8 @@
this.tableParams = this.params;
this.refresh();
},
- column(){
- this.userColumn=this.column;
+ tableColumn(){
+ this.column = this.tableColumn;
}
},
computed: {
@@ -111,6 +112,7 @@
return {
scPageSize: this.pageSize,
isActivat: true,
+ api: '',
emptyText: "暂无数据",
toggleIndex: 0,
tableData: [],
@@ -121,7 +123,8 @@
loading: false,
tableHeight:'100%',
tableParams: this.params,
- userColumn: [],
+ column: [],
+ columnSetting: false,
customColumnShow: false,
summary: {},
config: {
@@ -132,12 +135,23 @@
}
},
mounted() {
+
//判断是否开启自定义列
- if(this.tablename){
- this.getCustomColumn()
+ if(this.name) {
+ 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{
- this.userColumn = this.column
+ this.column = this.tableColumn
}
+
//判断是否静态数据
if(this.apiObj){
this.getData();
@@ -155,11 +169,6 @@
this.isActivat = false;
},
methods: {
- //获取列
- async getCustomColumn(){
- const userColumn = await config.columnSettingGet(this.tablename, this.column)
- this.userColumn = userColumn
- },
//获取数据
async getData(){
this.loading = true;
@@ -176,7 +185,9 @@
Object.assign(reqData, this.tableParams)
try {
- var res = await this.apiObj(reqData);
+
+ var res = this.api? await this.$http.get(this.api, reqData):await this.apiObj(reqData);
+
}catch(error){
this.loading = false;
this.emptyText = error.statusText;
@@ -237,15 +248,15 @@
this.getData()
},
//自定义变化事件
- columnSettingChange(userColumn){
- this.userColumn = userColumn;
+ columnSettingChange(column){
+ this.column = column;
this.toggleIndex += 1;
},
//自定义列保存
- async columnSettingSave(userColumn){
+ async columnSettingSave(column){
this.$refs.columnSetting.isSave = true
try {
- await config.columnSettingSave(this.tablename, userColumn)
+ await config.columnSettingSave(this.name, column)
}catch(error){
this.$message.error('保存失败')
this.$refs.columnSetting.isSave = false
@@ -257,9 +268,9 @@
async columnSettingBack(){
this.$refs.columnSetting.isSave = true
try {
- const column = await config.columnSettingReset(this.tablename, this.column)
- this.userColumn = column
- this.$refs.columnSetting.usercolumn = JSON.parse(JSON.stringify(this.userColumn||[]))
+ const column = await config.columnSettingReset(this.name, this.column)
+ this.column = column
+ this.$refs.columnSetting.column = JSON.parse(JSON.stringify(this.column||[]))
}catch(error){
this.$message.error('重置失败')
this.$refs.columnSetting.isSave = false
@@ -271,7 +282,7 @@
if(!this.remoteSort){
return false
}
- if(obj.column && obj.prop){
+ if(obj.tableColumn && obj.prop){
this.prop = obj.prop
this.order = obj.order
}else{
diff --git a/src/config/table.js b/src/config/table.js
index 91caa8b..7d8c655 100644
--- a/src/config/table.js
+++ b/src/config/table.js
@@ -1,6 +1,5 @@
//数据表格配置
import tool from '@/utils/tool'
-import http from "@/utils/request"
export default {
successCode: 200, //请求完成代码
pageSize: 20, //表格每一页条数
@@ -22,6 +21,7 @@ export default {
prop: 'prop', //规定排序字段名字段
order: 'order' //规定排序规格字段
},
+ configUrl: 'system/table/get',
/**
* 自定义列保存处理
* @tablename scTable组件的props->tablename
@@ -36,25 +36,6 @@ export default {
}, 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
diff --git a/src/utils/request.js b/src/utils/request.js
index 9095891..dcce7e4 100644
--- a/src/utils/request.js
+++ b/src/utils/request.js
@@ -1,210 +1,209 @@
import axios from 'axios';
-import { ElNotification, ElMessageBox } from 'element-plus';
+import {
+ ElNotification,
+ ElMessageBox
+} from 'element-plus';
import sysConfig from "@/config";
import tool from '@/utils/tool';
import router from '@/router';
-
-
axios.defaults.baseURL = sysConfig.API_URL
axios.defaults.timeout = sysConfig.TIMEOUT
-
// HTTP request 拦截器
axios.interceptors.request.use(
- (config) => {
- let token = tool.cookie.get("token");
- if(token){
- config.headers[sysConfig.TOKEN_NAME] = sysConfig.TOKEN_PREFIX + token
- }
- if(!sysConfig.REQUEST_CACHE && config.method == 'get'){
- config.params = config.params || {};
- config.params['_'] = new Date().getTime();
- }
- Object.assign(config.headers, sysConfig.HEADERS)
- return config;
- },
- (error) => {
- return Promise.reject(error);
- }
-);
-
+ (config) => {
+ let token = tool.cookie.get("token");
+ if (token) {
+ config.headers[sysConfig.TOKEN_NAME] = sysConfig.TOKEN_PREFIX + token
+ }
+ if (!sysConfig.REQUEST_CACHE && config.method == 'get') {
+ config.params = config.params || {};
+ config.params['_'] = new Date().getTime();
+ }
+ Object.assign(config.headers, sysConfig.HEADERS)
+ return config;
+ }, (error) => {
+ return Promise.reject(error);
+ });
//FIX 多个API同时401时疯狂弹窗BUG
let MessageBox_401_show = false
-
// HTTP response 拦截器
axios.interceptors.response.use(
- (response) => {
- return response;
- },
- (error) => {
- if (error.response) {
- if (error.response.status == 404) {
- ElNotification.error({
- title: '请求错误',
- message: "Status:404,正在请求不存在的服务器记录!"
- });
- } else if (error.response.status == 500) {
- ElNotification.error({
- title: '请求错误',
- message: error.response.data.message || "Status:500,服务器发生错误!"
- });
- } else if (error.response.status == 401) {
- if(!MessageBox_401_show){
- MessageBox_401_show = true
- ElMessageBox.confirm('当前用户已被登出或无权限访问当前资源,请尝试重新登录后再操作。', '无权限访问', {
- type: 'error',
- closeOnClickModal: false,
- center: true,
- confirmButtonText: '重新登录',
- beforeClose: (action, instance, done) => {
- MessageBox_401_show = false
- done()
- }
- }).then(() => {
- router.replace({path: '/login'});
- }).catch(() => {})
- }
- } else {
- ElNotification.error({
- title: '请求错误',
- message: error.message || `Status:${error.response.status},未知错误!`
- });
- }
- } else {
- ElNotification.error({
- title: '请求错误',
- message: "请求服务器无响应!"
- });
- }
-
- return Promise.reject(error.response);
- }
-);
-
+ (response) => {
+ return response;
+ }, (error) => {
+ if (error.response) {
+ if (error.response.status == 404) {
+ ElNotification.error({
+ title: '请求错误',
+ message: "Status:404,正在请求不存在的服务器记录!"
+ });
+ } else if (error.response.status == 500) {
+ ElNotification.error({
+ title: '请求错误',
+ message: error.response.data.message || "Status:500,服务器发生错误!"
+ });
+ } else if (error.response.status == 401) {
+ if (!MessageBox_401_show) {
+ MessageBox_401_show = true
+ ElMessageBox.confirm('当前用户已被登出或无权限访问当前资源,请尝试重新登录后再操作。', '无权限访问', {
+ type: 'error',
+ closeOnClickModal: false,
+ center: true,
+ confirmButtonText: '重新登录',
+ beforeClose: (action, instance, done) => {
+ MessageBox_401_show = false
+ done()
+ }
+ }).then(() => {
+ router.replace({
+ path: '/login'
+ });
+ }).catch(() => {})
+ }
+ } else {
+ ElNotification.error({
+ title: '请求错误',
+ message: error.message || `Status:${error.response.status},未知错误!`
+ });
+ }
+ } else {
+ ElNotification.error({
+ title: '请求错误',
+ message: "请求服务器无响应!"
+ });
+ }
+ return Promise.reject(error.response);
+ });
var http = {
-
- /** get 请求
- * @param {string} url 接口地址
- * @param {object} params 请求参数
- * @param {object} config 参数
- */
- get: function(url, params={}, config={}) {
- return new Promise((resolve, reject) => {
- axios({
- method: 'get',
- url: url,
- params: params,
- ...config
- }).then((response) => {
- resolve(response.data);
- }).catch((error) => {
- reject(error);
- })
- })
- },
-
- /** post 请求
- * @param {string} url 接口地址
- * @param {object} data 请求参数
- * @param {object} config 参数
- */
- post: function(url, data={}, config={}) {
- return new Promise((resolve, reject) => {
- axios({
- method: 'post',
- url: url,
- data: data,
- ...config
- }).then((response) => {
- resolve(response.data);
- }).catch((error) => {
- reject(error);
- })
- })
- },
-
- /** put 请求
- * @param {string} url 接口地址
- * @param {object} data 请求参数
- * @param {object} config 参数
- */
- put: function(url, data={}, config={}) {
- return new Promise((resolve, reject) => {
- axios({
- method: 'put',
- url: url,
- data: data,
- ...config
- }).then((response) => {
- resolve(response.data);
- }).catch((error) => {
- reject(error);
- })
- })
- },
-
- /** patch 请求
- * @param {string} url 接口地址
- * @param {object} data 请求参数
- * @param {object} config 参数
- */
- patch: function(url, data={}, config={}) {
- return new Promise((resolve, reject) => {
- axios({
- method: 'patch',
- url: url,
- data: data,
- ...config
- }).then((response) => {
- resolve(response.data);
- }).catch((error) => {
- reject(error);
- })
- })
- },
-
- /** delete 请求
- * @param {string} url 接口地址
- * @param {object} data 请求参数
- * @param {object} config 参数
- */
- delete: function(url, data={}, config={}) {
- return new Promise((resolve, reject) => {
- axios({
- method: 'delete',
- url: url,
- data: data,
- ...config
- }).then((response) => {
- resolve(response.data);
- }).catch((error) => {
- reject(error);
- })
- })
- },
-
- /** jsonp 请求
- * @param {string} url 接口地址
- * @param {string} name JSONP回调函数名称
- */
- jsonp: function(url, name='jsonp'){
- return new Promise((resolve) => {
- var script = document.createElement('script')
- var _id = `jsonp${Math.ceil(Math.random() * 1000000)}`
- script.id = _id
- script.type = 'text/javascript'
- script.src = url
- window[name] =(response) => {
- resolve(response)
- document.getElementsByTagName('head')[0].removeChild(script)
- try {
- delete window[name];
- }catch(e){
- window[name] = undefined;
- }
- }
- document.getElementsByTagName('head')[0].appendChild(script)
- })
- }
+ /** get 请求
+ * @param {string} url 接口地址
+ * @param {object} params 请求参数
+ * @param {object} config 参数
+ */
+ get: function(url, params = {}, config = {}) {
+ return new Promise((resolve, reject) => {
+ // 缓存存在, 优先使用缓存
+ const cacheKey = '';
+ if (typeof config.cache !== 'undefined' && !isNaN(config.cache) && config.cache > 0) {
+ let cacheKey = tool.crypto.MD5(url);
+ const cachedData = tool.data.get(cacheKey);
+ if (cachedData) {
+ return resolve(cachedData);
+ }
+ }
+ axios({
+ method: 'get',
+ url: url,
+ params: params,
+ ...config
+ }).then((response) => {
+ if (cacheKey) {
+ tool.data.set(cacheKey, response.data, config.cache);
+ }
+ resolve(response.data);
+ }).catch((error) => {
+ reject(error);
+ })
+ })
+ },
+ /** post 请求
+ * @param {string} url 接口地址
+ * @param {object} data 请求参数
+ * @param {object} config 参数
+ */
+ post: function(url, data = {}, config = {}) {
+ return new Promise((resolve, reject) => {
+ axios({
+ method: 'post',
+ url: url,
+ data: data,
+ ...config
+ }).then((response) => {
+ resolve(response.data);
+ }).catch((error) => {
+ reject(error);
+ })
+ })
+ },
+ /** put 请求
+ * @param {string} url 接口地址
+ * @param {object} data 请求参数
+ * @param {object} config 参数
+ */
+ put: function(url, data = {}, config = {}) {
+ return new Promise((resolve, reject) => {
+ axios({
+ method: 'put',
+ url: url,
+ data: data,
+ ...config
+ }).then((response) => {
+ resolve(response.data);
+ }).catch((error) => {
+ reject(error);
+ })
+ })
+ },
+ /** patch 请求
+ * @param {string} url 接口地址
+ * @param {object} data 请求参数
+ * @param {object} config 参数
+ */
+ patch: function(url, data = {}, config = {}) {
+ return new Promise((resolve, reject) => {
+ axios({
+ method: 'patch',
+ url: url,
+ data: data,
+ ...config
+ }).then((response) => {
+ resolve(response.data);
+ }).catch((error) => {
+ reject(error);
+ })
+ })
+ },
+ /** delete 请求
+ * @param {string} url 接口地址
+ * @param {object} data 请求参数
+ * @param {object} config 参数
+ */
+ delete: function(url, data = {}, config = {}) {
+ return new Promise((resolve, reject) => {
+ axios({
+ method: 'delete',
+ url: url,
+ data: data,
+ ...config
+ }).then((response) => {
+ resolve(response.data);
+ }).catch((error) => {
+ reject(error);
+ })
+ })
+ },
+ /** jsonp 请求
+ * @param {string} url 接口地址
+ * @param {string} name JSONP回调函数名称
+ */
+ jsonp: function(url, name = 'jsonp') {
+ return new Promise((resolve) => {
+ var script = document.createElement('script')
+ var _id = `jsonp${Math.ceil(Math.random() * 1000000)}`
+ script.id = _id
+ script.type = 'text/javascript'
+ script.src = url
+ window[name] = (response) => {
+ resolve(response)
+ document.getElementsByTagName('head')[0].removeChild(script)
+ try {
+ delete window[name];
+ } catch (e) {
+ window[name] = undefined;
+ }
+ }
+ document.getElementsByTagName('head')[0].appendChild(script)
+ })
+ }
}
-
-export default http;
+export default http;
\ No newline at end of file
diff --git a/src/views/system/menu/index.vue b/src/views/system/menu/index.vue
index 3e457c7..41cc61e 100644
--- a/src/views/system/menu/index.vue
+++ b/src/views/system/menu/index.vue
@@ -46,7 +46,7 @@
import save from './save'
export default {
- name: "settingMenu",
+ name: "systemmenu",
components: {
save
},
diff --git a/src/views/system/menu/save.vue b/src/views/system/menu/save.vue
index 26c9510..27e4bee 100644
--- a/src/views/system/menu/save.vue
+++ b/src/views/system/menu/save.vue
@@ -46,7 +46,6 @@
-
隐藏菜单
@@ -56,6 +55,9 @@
+
+
+
diff --git a/src/views/system/setting/index.vue b/src/views/system/setting/index.vue
index 749054a..3dbebdb 100644
--- a/src/views/system/setting/index.vue
+++ b/src/views/system/setting/index.vue
@@ -37,7 +37,7 @@