Commit ee49135e by fukai

配套优化前端pageId刷新

parent 6a5f5673
......@@ -15,6 +15,7 @@ import i18n from "./lang";
import CustomComponent from "./components";
import vuefunc from "./utils/vuefunc";
import "./permission";
import EventService,{LOGIN,LOGOUT} from "~/service/EventService";
window.SUCCESS = "AAAAAA";
......@@ -22,6 +23,20 @@ Vue.use(ElementUI, { size: "small", i18n: (key, value) => i18n.t(key, value) });
Vue.use(CustomComponent);
Vue.use(vuefunc);
function resetCache(){
window.GLOBAL_CACHE = {PAGEID_CACHE:new Set()};
}
//初始化cache
resetCache();
//登录后重置
EventService.on(LOGIN,()=>{
resetCache();
});
//退出后重置
EventService.on(LOGOUT,()=>{
resetCache();
});
new Vue({
el: "#app",
store,
......
......@@ -90,9 +90,16 @@ export default {
},
async init(params) {
const loading = this.loading("交易加载中")
let rtnmsg = await Api.post(this.requestPrefix + "/init", { params })
let prePageId = this.$route.params.prePageId || "";
console.log("init/prePageId:"+prePageId);
let data = { params,prePageId };
let rtnmsg = await Api.post(this.requestPrefix + "/init", data)
if (rtnmsg.respCode == SUCCESS) {
this.updateValueSet(rtnmsg.codeSet)
//添加pageId
if(rtnmsg.data.pageId)
window.GLOBAL_CACHE.PAGEID_CACHE.add(rtnmsg.data.pageId);
}
loading.close()
return rtnmsg
......@@ -203,5 +210,11 @@ export default {
}
});
}
},
async beforeDestroy(){
if(!this.root && this.model && this.model.pageId){
//回收pageId
window.GLOBAL_CACHE.PAGEID_CACHE.delete(this.model.pageId);
}
}
}
\ No newline at end of file
......@@ -5,11 +5,25 @@ import RequestManager from './RequestManager.js';
export const BASE_HOST = "/gjjs"
export const BASE_URI=BASE_HOST+"";
const instance = axios.create({
baseURL: BASE_URI,
timeout: 5000,
method: 'post',
export const AxiosInstance = axios.create({
});
//对全局的业务数据请求使用拦截器
AxiosInstance.interceptors.request.use(function(config){
if(window.GLOBAL_CACHE && window.GLOBAL_CACHE.PAGEID_CACHE){
const key = "CUR-PAGE-IDS";
let pageIds = [...window.GLOBAL_CACHE.PAGEID_CACHE].join(",");
if(!config.headers){
config.headers = {key:pageIds};
}else if(!config.headers[key]){
config.headers[key] = pageIds;
}
}
return config;
},function(error){
return Promise.reject(error);
})
const CODE_KEY = "respCode"
const MESSAGE_KEY = "respMsg"
......@@ -26,7 +40,7 @@ export default class Api
if(url!= `${BASE_URI}login` && token)
headers.token = token;
return new Promise( (resolve, reject) =>{
axios.get(url,data,{
AxiosInstance.get(url,data,{
headers,
timeout: 50000,
......@@ -74,8 +88,13 @@ export default class Api
if (typeof data === "function") {
data = await data()
}
let curPid = data.pageId || "";
let prePid = data.prePageId || "";
//设置PAGEID
headers["CUR-PID"] = curPid;
headers["PRE-PID"] = prePid;
return new Promise( (resolve, reject) =>{
axios.post(url,data,{
AxiosInstance.post(url,data,{
headers,
method,
timeout: 120000,
......@@ -139,4 +158,8 @@ export default class Api
{
return this._get(BASE_HOST+url,data)
}
static postAsync(url,data){
return this._post.call(url,data);
}
}
\ No newline at end of file
/**
* 自定义的事件触发器
*/
export default class EventService {
static on(key, fn){
if(!this.events[key]){
this.events[key] = [];
}
for(let originFn of this.events[key]){
if(originFn === fn){
return;
}
}
this.events[key].push(fn);
return ()=>{
this.off(key,fn);
}
}
static off(key,fn){
if(!this.events[key]){
return;
}
const fns = this.events[key];
for(let i=0;i<fns.length;i++){
if(fns[i] == fn){
fns.splice(i,1);
return;
}
}
}
static async emit(key,arg){
if(!this.events[key]){
return;
}
const results = [];
const fns = this.events[key];
for(let i = 0;i<fns.length;i++){
let result;
try{
result = await fns[i](arg);
}catch(error){
}
results.push(result);
}
return results;
}
}
EventService.events = {}
const LOGIN="LOGIN"
const LOGOUT="LOGOUT"
export {LOGIN,LOGOUT}
\ No newline at end of file
......@@ -13,6 +13,10 @@
</c-function-btn>
<el-form :model="model" :rules="rules" ref="modelForm" label-width="120px" label-position="right" size="small"
:validate-on-rule-change="false">
<el-form-item label="test">
<c-mul-row-input v-model="testVal" v-on:input="onInput" :rows="3" :cols="5" :charmod="0"></c-mul-row-input>
<pre>{{testVal}}</pre>
</el-form-item>
<c-tabs :value="tabVal" ref="elment" type="card" @tab-click="tabClick">
<el-tab-pane label="基本信息" name="ovwp">
<!--PD000001 -->
......@@ -167,6 +171,7 @@ export default {
data() {
return {
tabVal: "ovwp",
testVal: "",
trnName: "ditopn",
model: new Ditopn().data,
customModel: new customDitopn().data,
......@@ -184,6 +189,9 @@ export default {
};
},
methods: {
onInput(val){
console.log(val)
}
},
created: async function () {
console.log("进入ditopn交易");
......
......@@ -222,6 +222,7 @@
<script>
import cPage from "../../components/c-page.vue";
import Api from "~/service/Api";
import EventService, {LOGOUT} from "~/service/EventService";
import { changeLang } from "~/service/business/lang";
export default {
......@@ -281,6 +282,7 @@ export default {
},
methods: {
logout() {
EventService.emit(LOGOUT);
this.$store.commit("UserContext/setLogout");
this.$router.push("/login");
// window.location.href = "/#/login"
......
......@@ -65,6 +65,8 @@
import Utils from "~/utils";
import { createNamespacedHelpers } from "vuex";
import axios from "axios";
import EventService, {LOGIN} from "~/service/EventService";
const { mapState, mapMutations, mapActions } =
createNamespacedHelpers("UserContext");
......@@ -96,6 +98,7 @@ export default {
userId: this.loginForm.username,
token: Utils.generateUUID(),
});
EventService.emit(LOGIN)
// 电证登录
const dzUsr = usrMap[this.loginForm.username === "ZL" ? "ZL" : "MBF"];
const headers = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment