Blame view

src/components/home/m-dropdown/m-dropdown.js 2.89 KB
simon committed
1 2 3 4 5 6 7 8 9
import {
	mapState
} from 'vuex'

import api from '@/api/api'
import {
	httpPost
} from '@/api/fetch-api.js'

1  
joe committed
10 11
import { gotoVHIS } from '@/utils/biz.js';

simon committed
12 13 14 15 16 17 18 19
export default {
	name: "DropDownList",
	data() {
		return {
			navList: [],
			activeNames: [],
			activeName: [],
			activeIndex: -1,
simon committed
20
			borderBoo: false
simon committed
21 22 23
		};
	},
	props: {
simon committed
24 25
		visible: {
			type: Boolean,
1  
joe committed
26
			default() {
simon committed
27 28 29
				return false;
			}
		},
simon committed
30 31
		type: {
			type: String,
1  
joe committed
32
			default() {
simon committed
33 34 35
				return "nav";
			}
		},
simon committed
36 37
		langList: {
			type: Array,
1  
joe committed
38
			default() {
simon committed
39 40 41 42 43 44 45 46
				return [];
			}
		},
		// 显示/隐藏移动端导航
		showDropdownM: {
			type: Function,
			default: null
		},
simon committed
47 48
	},
	computed: {
joe committed
49 50 51 52
		...mapState({
			isSmallScreen: state => state.isSmallScreen,
			userInfo: state => state.userInfo
		}),
simon committed
53 54 55 56 57 58 59 60
		locale() {
			return this.$i18n.locale || 'tc';
		},
		i18n() {
			return this.$i18n.messages && this.$i18n.locale ? this.$i18n.messages[this.$i18n.locale] : {};
		},
	},
	methods: {
simon committed
61
		// 跳转菜单
simon committed
62 63 64
		onClickHandler(item) {
			let path = item && item.path || "";
			if (path) {
simon committed
65
				this.showDropdownM('');
simon committed
66 67 68
				this.$router.push({
					path: path
				})
1  
joe committed
69 70 71 72 73 74 75 76 77 78 79 80
			} else {
				let value = item && item.value || null;
				if (value) {
					switch (value) {
						case "logout":
							this.loginHandler();
							break;
						case "gotoVHIS":
							gotoVHIS(this.locale);
							break;
					}
				}
simon committed
81 82
			}
		},
1  
joe committed
83 84 85 86 87 88 89 90
		loginHandler() {
			httpPost({
				url: api.logout
			}).then(() => {
				this.$store.commit("SET_USER_INFO", null);
				this.showLogoutTip();
			});
		},
simon committed
91
		// 点击item
simon committed
92 93 94
		onChangeHandler(evt) {
			this.activeIndex = evt;
		},
simon committed
95 96 97 98
		/**
		 * 设置语言
		 */
		setLangHandler(curData) {
simon committed
99
			this.showDropdownM('');
simon committed
100 101 102 103 104 105 106
			// 如果是语言设置,则设置语言
			let lang = curData.value;
			this.$i18n.locale = lang;
			localStorage.setItem("lang", lang);
			this.sTitle = curData.name;
			window.location.reload();
		},
simon committed
107
		initData() {
simon committed
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
			let navList = [];
			if (this.type == "nav") {
				navList = this.i18n.nav.navList;
				navList.forEach(element => {
					this.activeNames.push(
						[]
					)
				});
			} else if (this.type == "login") {
				// 构建登陆页面
				let i18n = this.$i18n.messages[this.$i18n.locale] || {};
				let menuData = JSON.parse(JSON.stringify(i18n.nav.loginData));
				let list = [];
				if (this.userInfo && this.userInfo.name) {
					menuData.name = this.userInfo.name;
					menuData.list.forEach(element => {
						if (element.type == "auth") {
							list.push(element);
						}
					});
				} else {
					menuData.list.forEach(element => {
						if (element.type == "noAuth") {
							list.push(element);
						}
					});
				}
				// menuData.list = list;
				navList = list;
joe committed
137
				// console.log("navList:", navList);
simon committed
138
			}
simon committed
139
			this.navList = navList;
simon committed
140

simon committed
141 142 143 144 145
		}
	},
	created() {
		this.initData();
	},
simon committed
146 147 148 149 150
	watch: {
		visible(newVal, oldVal) {
			this.$nextTick(() => {
				this.$refs.panel.scrollTop = 0;
			});
joe committed
151 152 153
		},
		userInfo(val) {
			this.initData();
simon committed
154 155
		}
	},
simon committed
156
};