Blame view

src/components/home/m-dropdown/m-dropdown.js 3.28 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
		onClickHandler(item) {
			let path = item && item.path || "";
joe committed
64
			this.showDropdownM('');
simon committed
65 66 67 68
			if (path) {
				this.$router.push({
					path: path
				})
1  
joe committed
69 70 71 72
			} else {
				let value = item && item.value || null;
				if (value) {
					switch (value) {
joe committed
73 74 75
						case "login":
							this.onLoginHandler();
							break;
1  
joe committed
76
						case "logout":
joe committed
77
							this.logoutHandler();
1  
joe committed
78 79
							break;
						case "gotoVHIS":
joe committed
80
							gotoVHIS(this.$i18n.locale);
1  
joe committed
81 82 83
							break;
					}
				}
simon committed
84 85
			}
		},
joe committed
86 87 88
		onLoginHandler() {
			if (this.$route.name == "login") {
				return;
joe committed
89
			} else if (this.$route.name == "register" || this.$route.name == "passwordFind") {
joe committed
90 91 92 93 94 95 96
				this.$router.push({ path: "/login" });
			} else {
				let callback = this.$route.fullPath;
				this.$router.push({ path: "/login?callback=" + callback });
			}
		},
		logoutHandler() {
1  
joe committed
97 98 99 100 101 102 103
			httpPost({
				url: api.logout
			}).then(() => {
				this.$store.commit("SET_USER_INFO", null);
				this.showLogoutTip();
			});
		},
simon committed
104
		// 点击item
simon committed
105 106 107
		onChangeHandler(evt) {
			this.activeIndex = evt;
		},
simon committed
108 109 110 111
		/**
		 * 设置语言
		 */
		setLangHandler(curData) {
simon committed
112
			this.showDropdownM('');
simon committed
113 114 115 116 117 118 119
			// 如果是语言设置,则设置语言
			let lang = curData.value;
			this.$i18n.locale = lang;
			localStorage.setItem("lang", lang);
			this.sTitle = curData.name;
			window.location.reload();
		},
simon committed
120
		initData() {
simon committed
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
			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
150
				// console.log("navList:", navList);
simon committed
151
			}
simon committed
152
			this.navList = navList;
simon committed
153

simon committed
154 155 156 157 158
		}
	},
	created() {
		this.initData();
	},
simon committed
159 160 161 162 163
	watch: {
		visible(newVal, oldVal) {
			this.$nextTick(() => {
				this.$refs.panel.scrollTop = 0;
			});
joe committed
164 165 166
		},
		userInfo(val) {
			this.initData();
simon committed
167 168
		}
	},
simon committed
169
};