[OHIF-Viewers]医疗数字阅片-医学影像-redux-token实操(1)

2020-07-22 17:14:28 浏览数 (1)

[OHIF-Viewers]医疗数字阅片-医学影像-redux-token实操

需要更改地方

修改: platform/core/src/redux/actions.js 修改: platform/core/src/redux/reducers/index.js 新文件: platform/core/src/redux/reducers/token.js 修改: platform/viewer/src/App.js

actions.js

代码语言:javascript复制
 export const setToken =token=>({
   type:'SET_TOKEN',
   token
 })

setStudyData,
setServers,
 setToken,
};

reducers/index.js

代码语言:javascript复制
import viewports from './viewports';
 import Token from './token'
……
viewports,
 Token,

reducers/token.js

代码语言:javascript复制
//默认state
export const defaultState = {
  token: 1,
};

const Token = (state = defaultState, action) => {
  switch (action.type) {
    case 'SET_TOKEN': //不使用样板文件
      // return { ...state, token: action.token }; //旧的state一起返回
          return action.token;//只返回新值
    default:
      return state;
  }
};

export default Token;

src/App.js

代码语言:javascript复制
 import {setToken} from "@ohif/core/src/redux/actions";//直连引入setToken
//设置token
 store.dispatch(setToken(this.getQueryToken('token')?this.getQueryToken('token'):'00'));
 console.log(store.getState().token);

 //获取url 参数
 getQueryToken(name) {
        var reg = new RegExp("(^|&)"   name   "=([^&]*)(&|$)", "i");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
         return null;
     }

0 人点赞