Browse Source

新增tab对象简化页签操作

tags/v3.3.0
RuoYi 3 years ago
parent
commit
adcb6194c8
  1. 19
      ruoyi-ui/src/layout/components/TagsView/index.vue
  2. 3
      ruoyi-ui/src/plugins/index.js
  3. 68
      ruoyi-ui/src/plugins/tab.js
  4. 2
      ruoyi-ui/src/store/modules/tagsView.js
  5. 15
      ruoyi-ui/src/utils/request.js
  6. 4
      ruoyi-ui/src/views/monitor/job/log.vue
  7. 14
      ruoyi-ui/src/views/system/dict/data.vue
  8. 4
      ruoyi-ui/src/views/system/role/authUser.vue
  9. 4
      ruoyi-ui/src/views/system/user/authRole.vue
  10. 3
      ruoyi-ui/src/views/system/user/profile/resetPwd.vue
  11. 3
      ruoyi-ui/src/views/system/user/profile/userInfo.vue
  12. 4
      ruoyi-ui/src/views/tool/gen/editTable.vue

19
ruoyi-ui/src/layout/components/TagsView/index.vue

@ -152,31 +152,24 @@ export default {
}) })
}, },
refreshSelectedTag(view) { refreshSelectedTag(view) {
this.$store.dispatch('tagsView/delCachedView', view).then(() => { this.$tab.refreshPage(view);
const { fullPath } = view
this.$nextTick(() => {
this.$router.replace({
path: '/redirect' + fullPath
})
})
})
}, },
closeSelectedTag(view) { closeSelectedTag(view) {
this.$store.dispatch('tagsView/delView', view).then(({ visitedViews }) => { this.$tab.closePage(view).then(({ visitedViews }) => {
if (this.isActive(view)) { if (this.isActive(view)) {
this.toLastView(visitedViews, view) this.toLastView(visitedViews, view)
} }
}) })
}, },
closeRightTags() { closeRightTags() {
this.$store.dispatch('tagsView/delRightTags', this.selectedTag).then(visitedViews => { this.$tab.closeRightPage(this.selectedTag).then(visitedViews => {
if (!visitedViews.find(i => i.fullPath === this.$route.fullPath)) { if (!visitedViews.find(i => i.fullPath === this.$route.fullPath)) {
this.toLastView(visitedViews) this.toLastView(visitedViews)
} }
}) })
}, },
closeLeftTags() { closeLeftTags() {
this.$store.dispatch('tagsView/delLeftTags', this.selectedTag).then(visitedViews => { this.$tab.closeLeftPage(this.selectedTag).then(visitedViews => {
if (!visitedViews.find(i => i.fullPath === this.$route.fullPath)) { if (!visitedViews.find(i => i.fullPath === this.$route.fullPath)) {
this.toLastView(visitedViews) this.toLastView(visitedViews)
} }
@ -184,12 +177,12 @@ export default {
}, },
closeOthersTags() { closeOthersTags() {
this.$router.push(this.selectedTag).catch(()=>{}); this.$router.push(this.selectedTag).catch(()=>{});
this.$store.dispatch('tagsView/delOthersViews', this.selectedTag).then(() => { this.$tab.closeOtherPage(this.selectedTag).then(() => {
this.moveToCurrentTag() this.moveToCurrentTag()
}) })
}, },
closeAllTags(view) { closeAllTags(view) {
this.$store.dispatch('tagsView/delAllViews').then(({ visitedViews }) => { this.$tab.closeAllPage().then(({ visitedViews }) => {
if (this.affixTags.some(tag => tag.path === this.$route.path)) { if (this.affixTags.some(tag => tag.path === this.$route.path)) {
return return
} }

3
ruoyi-ui/src/plugins/index.js

@ -1,3 +1,4 @@
import tab from './tab'
import auth from './auth' import auth from './auth'
import cache from './cache' import cache from './cache'
import modal from './modal' import modal from './modal'
@ -5,6 +6,8 @@ import download from './download'
export default { export default {
install(Vue) { install(Vue) {
// 页签操作
Vue.prototype.$tab = tab
// 认证对象 // 认证对象
Vue.prototype.$auth = auth Vue.prototype.$auth = auth
// 缓存对象 // 缓存对象

68
ruoyi-ui/src/plugins/tab.js

@ -0,0 +1,68 @@
import store from '@/store'
import router from '@/router';
export default {
// 刷新当前tab页签
refreshPage(obj) {
const { path, matched } = router.currentRoute;
if (obj === undefined) {
matched.forEach((m) => {
if (m.components && m.components.default && m.components.default.name) {
if (!['Layout', 'ParentView'].includes(m.components.default.name)) {
obj = { name: m.components.default.name, path: path };
}
}
});
}
return store.dispatch('tagsView/delCachedView', obj).then(() => {
const { path } = obj
router.replace({
path: '/redirect' + path
})
})
},
// 关闭当前tab页签,打开新页签
closeOpenPage(obj) {
store.dispatch("tagsView/delView", router.currentRoute);
if (obj !== undefined) {
return router.push(obj);
}
},
// 关闭指定tab页签
closePage(obj) {
if (obj === undefined) {
return store.dispatch('tagsView/delView', router.currentRoute).then(({ lastPath }) => {
return router.push(lastPath || '/');
});
}
return store.dispatch('tagsView/delView', obj);
},
// 关闭所有tab页签
closeAllPage() {
return store.dispatch('tagsView/delAllViews');
},
// 关闭左侧tab页签
closeLeftPage(obj) {
return store.dispatch('tagsView/delLeftTags', obj || router.currentRoute);
},
// 关闭右侧tab页签
closeRightPage(obj) {
return store.dispatch('tagsView/delRightTags', obj || router.currentRoute);
},
// 关闭其他tab页签
closeOtherPage(obj) {
return store.dispatch('tagsView/delOthersViews', obj || router.currentRoute);
},
// 添加tab页签
addPage(title, url) {
var obj = { path: url, meta: { title: title } }
store.dispatch('tagsView/addView', obj);
return router.push(url);
},
// 修改tab页签
updatePage(obj) {
return store.dispatch('tagsView/updateVisitedView', obj);
}
}

2
ruoyi-ui/src/store/modules/tagsView.js

@ -14,7 +14,7 @@ const mutations = {
}, },
ADD_CACHED_VIEW: (state, view) => { ADD_CACHED_VIEW: (state, view) => {
if (state.cachedViews.includes(view.name)) return if (state.cachedViews.includes(view.name)) return
if (!view.meta.noCache) { if (view.meta && !view.meta.noCache) {
state.cachedViews.push(view.name) state.cachedViews.push(view.name)
} }
}, },

15
ruoyi-ui/src/utils/request.js

@ -48,19 +48,16 @@ service.interceptors.response.use(res => {
return res.data return res.data
} }
if (code === 401) { if (code === 401) {
let doms = document.getElementsByClassName('el-message-box')[0] MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', {
if(doms === undefined){
MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', {
confirmButtonText: '重新登录', confirmButtonText: '重新登录',
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'
} }
).then(() => { ).then(() => {
store.dispatch('LogOut').then(() => { store.dispatch('LogOut').then(() => {
location.href = '/index'; location.href = '/index';
}) })
}).catch(() => {}); }).catch(() => {});
}
return Promise.reject('无效的会话,或者会话已过期,请重新登录。') return Promise.reject('无效的会话,或者会话已过期,请重新登录。')
} else if (code === 500) { } else if (code === 500) {
Message({ Message({

4
ruoyi-ui/src/views/monitor/job/log.vue

@ -245,8 +245,8 @@ export default {
}, },
// //
handleClose() { handleClose() {
this.$store.dispatch("tagsView/delView", this.$route); const obj = { path: "/monitor/job" };
this.$router.push({ path: "/monitor/job" }); this.$tab.closeOpenPage(obj);
}, },
/** 搜索按钮操作 */ /** 搜索按钮操作 */
handleQuery() { handleQuery() {

14
ruoyi-ui/src/views/system/dict/data.vue

@ -79,6 +79,15 @@
v-hasPermi="['system:dict:export']" v-hasPermi="['system:dict:export']"
>导出</el-button> >导出</el-button>
</el-col> </el-col>
<el-col :span="1.5">
<el-button
type="warning"
plain
icon="el-icon-close"
size="mini"
@click="handleClose"
>关闭</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row> </el-row>
@ -316,6 +325,11 @@ export default {
this.queryParams.pageNum = 1; this.queryParams.pageNum = 1;
this.getList(); this.getList();
}, },
//
handleClose() {
const obj = { path: "/system/dict" };
this.$tab.closeOpenPage(obj);
},
/** 重置按钮操作 */ /** 重置按钮操作 */
resetQuery() { resetQuery() {
this.resetForm("queryForm"); this.resetForm("queryForm");

4
ruoyi-ui/src/views/system/role/authUser.vue

@ -153,8 +153,8 @@ export default {
}, },
// //
handleClose() { handleClose() {
this.$store.dispatch("tagsView/delView", this.$route); const obj = { path: "/system/role" };
this.$router.push({ path: "/system/role" }); this.$tab.closeOpenPage(obj);
}, },
/** 搜索按钮操作 */ /** 搜索按钮操作 */
handleQuery() { handleQuery() {

4
ruoyi-ui/src/views/system/user/authRole.vue

@ -109,8 +109,8 @@ export default {
}, },
/** 关闭按钮 */ /** 关闭按钮 */
close() { close() {
this.$store.dispatch("tagsView/delView", this.$route); const obj = { path: "/system/user" };
this.$router.push({ path: "/system/user" }); this.$tab.closeOpenPage(obj);
}, },
}, },
}; };

3
ruoyi-ui/src/views/system/user/profile/resetPwd.vue

@ -64,8 +64,7 @@ export default {
}); });
}, },
close() { close() {
this.$store.dispatch("tagsView/delView", this.$route); this.$tab.closePage();
this.$router.push({ path: "/index" });
} }
} }
}; };

3
ruoyi-ui/src/views/system/user/profile/userInfo.vue

@ -68,8 +68,7 @@ export default {
}); });
}, },
close() { close() {
this.$store.dispatch("tagsView/delView", this.$route); this.$tab.closePage();
this.$router.push({ path: "/index" });
} }
} }
}; };

4
ruoyi-ui/src/views/tool/gen/editTable.vue

@ -211,8 +211,8 @@ export default {
}, },
/** 关闭按钮 */ /** 关闭按钮 */
close() { close() {
this.$store.dispatch("tagsView/delView", this.$route); const obj = { path: "/tool/gen", query: { t: Date.now(), pageNum: this.$route.query.pageNum } };
this.$router.push({ path: "/tool/gen", query: { t: Date.now(), pageNum: this.$route.query.pageNum } }) this.$tab.closeOpenPage(obj);
} }
}, },
mounted() { mounted() {

Loading…
Cancel
Save