Commit 8da409ca authored by 周远喜's avatar 周远喜

用户信息缓存展示

parent ea9d2d99
...@@ -2,22 +2,20 @@ ...@@ -2,22 +2,20 @@
<Poptip placement="bottom-start" trigger="hover" width="240" transfer> <Poptip placement="bottom-start" trigger="hover" width="240" transfer>
<label :class="css">{{ user.name }}</label> <label :class="css">{{ user.name }}</label>
<div slot="content"> <div slot="content">
<Avatar <Avatar v-if="user.face" size="large" :src="user.face"></Avatar>
v-if="user.face"
size="large"
:src="user.face"
></Avatar>
<Avatar <Avatar
v-else v-else
size="large" size="large"
style="color: #f56a00;background-color: #fde3cf; text-align:center" style="color: #f56a00;background-color: #fde3cf; text-align:center"
:icon="user.gender=='男'?'md-person':'md-woman'" :icon="user.gender=='男'?'md-person':'md-woman'"
></Avatar> ></Avatar>
<div>姓名:{{ user.name }} <div>
姓名:{{ user.name }}
<tag v-if="user.isDeleted">已删除</tag> <tag v-if="user.isDeleted">已删除</tag>
</div> </div>
<div>状态: <div>
<state :value="user.status" type="tag" code="User.base.status"/> 状态:
<state :value="user.status" type="tag" code="User.base.status" />
</div> </div>
<div>性别:{{ user.gender }}</div> <div>性别:{{ user.gender }}</div>
<div>部门:{{ user.department }}</div> <div>部门:{{ user.department }}</div>
...@@ -27,7 +25,7 @@ ...@@ -27,7 +25,7 @@
</template> </template>
<script> <script>
export default { export default {
name: 'User', name: "User",
props: { props: {
value: { value: {
type: [Number, String], type: [Number, String],
...@@ -38,58 +36,55 @@ export default { ...@@ -38,58 +36,55 @@ export default {
return { return {
user: { user: {
name: this.value, name: this.value,
face: '', face: "",
gender: '', gender: "",
roles: '', roles: "",
department: '', status:0,
loginName: '', department: "",
loginName: "",
id: 0 id: 0
}, },
css:"s0" css: "s0"
} };
}, },
mounted() { mounted() {
//{"id":77,"name":"杨华馥","gender":"男","department":"北京生产车间","roles":"admin","status":1,"isDeleted":false} //{"id":77,"name":"杨华馥","gender":"男","department":"北京生产车间","roles":"admin","status":1,"isDeleted":false}
this.load() this.load();
}, },
methods: { methods: {
load() { load() {
if (this.value) { if (this.value) {
var user = this.$store.getters.getUser(this.value) var user = this.$store.getters.getUser(this.value);
if (user) { if (user) {
this.user = user this.user = user;
} else { if (this.user.isDeleted) {
this.$api this.css = "s2";
.get(`${systemUrl}/user/getuser`, { id: this.value }) } else if (this.user.status == 1) {
.then((r) => { this.css = "s1";
// alert(JSON.stringify( r.result)) }
if (r.success) { if (this.user.face) {
this.user = r.result this.user.face = fileUrlDown + this.user.face;
if(this.user.isDeleted){ }
this.css="s2"
}else if(this.user.status==1){
this.css="s1"
}
if(this.user.face){
this.user.face=fileUrlDown+this.user.face;
}
// this.$store.commit('addUser', r.result)
}
})
} }
} }
} }
}, },
watch: { watch: {
value(v) { value(v) {
if (v > 0) this.load() if (v > 0) this.load();
} }
} }
} };
</script> </script>
<style lang="less"> <style lang="less">
.s2{color: red;} .s2 {
.s1{color: #333} color: red;
.s0{color:#ddd} }
.s1 {
color: #333;
}
.s0 {
color: #ddd;
}
</style> </style>
\ No newline at end of file
import createVuexAlong from 'vuex-along' import createVuexAlong from 'vuex-along'
import Api from '@/plugins/request' import Api from '@/plugins/request'
export const state = () => ({ export const state=()=>({
counter: 0, counter:0,
dictionary: new Map(), //所有字典项 dictionary: new Map(),//所有字典项
userMap: [], //所有用户缓存; userMap:new Map(),//所有用户缓存;
userInfo: { userInfo:{
userId: 0, userId:0,
userName: "" userName:""
}, }
cart:[],
count: 0,
countAps:0,//aps排产
countAi:0,//智能排产
countAll:0,//整机排产
countRun:0,//流水排产
}) })
export const getters = { export const getters={
dictionaryByKey: (state) => (key) => { dictionaryByKey: (state) => (key) => {
if(state.dictionary){
return;
}
let result = []; let result = [];
let items = state.dictionary.get(key); let items = state.dictionary.get(key);
if (items) { if (items) {
...@@ -25,79 +22,51 @@ export const getters = { ...@@ -25,79 +22,51 @@ export const getters = {
} }
return result; return result;
}, },
getUser: state => key => { getUser:(state)=>key=>{
// try{ // debugger
// if(state.userMap.has(key)){ if(state.userMap&&state.userMap.get){
// return state.userMap.get(key); return state.userMap.get(key);
// }
// }catch(e){
// console.log(e);
// }
let user = state.userMap.filter(u => {
return u.id == key
});
if (user.length > 0) {
return user[0]
} else {
return null;
} }
} }
} }
export const mutations = { export const mutations={
increment(state) { increment(state){
state.counter++ state.counter++
}, },
setUserInfo(state, userInfo) { setUserInfo(state, userInfo) {
state.userInfo = userInfo; state.userInfo = userInfo;
// sessionStorage.setItem("userInfo", JSON.stringify(userInfo)); // sessionStorage.setItem("userInfo", JSON.stringify(userInfo));
// sessionStorage.setItem("token", userInfo.token); // sessionStorage.setItem("token", userInfo.token);
}, },
addUser(state, user) { setUsers(state,users){
state.userMap.push(user); state.userMap=users;
}, },
setDictionary(state, dictionary) { addUser(state,user){
state.dictionary = dictionary; state.userMap.push(user);
}, },
setCart(state, cart) { setDictionary(state, dictionary) {
state.cart = cart; state.dictionary = dictionary;
}, },
setCartCount(state, count) {
state.count = count;
},
setCountAps(state, count) {//设置aps排产数量
state.countAps = count;
},
setCountAi(state, count) {//设置智能排产数量
state.countAi = count;
},
setCountAll(state, count) {//设置整机排产数量
state.countAll = count;
},
setCountRun(state, count) {//设置流水排产数量
state.countRun = count;
}
} }
export const actions = { export const actions={
async loadUser({ async loadUser({commit},key){
commit
}, key) { let { result } = await Api.get(`${systemUrl}/user/getuser`,{id:key});
console.warn("result",result)
let { commit("addUser",result);
result },
} = await this.$api.get(`${systemUrl}/user/getuser`, { async loadUsers({commit}){
id: key let { result } = await Api.get(`${systemUrl}/user/getuserlist`);
var map=new Map();
result.map(u=>{
map.set(u.id,u);
}); });
console.warn("result", result) commit("setUsers",map)
commit("addUser", result);
}, },
async loadDictionary({ async loadDictionary({ commit }) {
commit
}) {
let url = `${systemUrl}/Dictionary/GetAll` let url = `${systemUrl}/Dictionary/GetAll`
let { let { result } = await Api.get(url);
result
} = await Api.get(url);
var map = new Map(); var map = new Map();
...@@ -110,20 +79,20 @@ export const actions = { ...@@ -110,20 +79,20 @@ export const actions = {
} }
} }
export const plugins = [ export const plugins= [
createVuexAlong({ createVuexAlong({
// 设置保存的集合名字,避免同站点下的多项目数据冲突 // 设置保存的集合名字,避免同站点下的多项目数据冲突
name: "hyhmes", name: "hyhmes",
local: { local: {
list: ["hyhmes"], list: ["hyhmes"],
// 过滤模块 ma 数据, 将其他的存入 localStorage // 过滤模块 ma 数据, 将其他的存入 localStorage
isFilter: true, isFilter: true,
}, },
session: { session: {
// 保存模块 ma 中的 a1 到 sessionStorage // 保存模块 ma 中的 a1 到 sessionStorage
list: ["hyhmes.session"], list: ["hyhmes.session"],
}, },
}), }),
] ]
//设置 strict 为不严格模式,即可在actions中修改state //设置 strict 为不严格模式,即可在actions中修改state
export const strict = false; export const strict=false;
\ No newline at end of file
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