Blame view

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

export default {
	name: "DropDownList",
	data() {
		return {
			activeIndex: 0,
simon committed
10
			sTitle: this.dataObj && this.dataObj.name || '',
simon committed
11 12 13 14 15 16 17 18 19
		};
	},
	props: {
		type: {
			type: String,
			default () {
				return "nav";
			}
		},
simon committed
20 21
		dataObj: {
			type: Object,
simon committed
22
			default () {
simon committed
23
				return {};
simon committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
			}
		},
		dataList: {
			type: Array,
			default () {
				return [];
			}
		},
		labelProperty: {
			type: String,
			default () {
				return "name";
			}
		}
	},
	directives: {
		dpl: {
			bind(el) {
				el.style.display = "none";
			}
		}
	},
	methods: {
simon committed
47 48 49 50 51 52 53 54
		onNavHandler() {
			let path = this.dataObj && this.dataObj.path || "";
			if (path) {
				this.$router.push({
					path: path
				})
			}
		},
simon committed
55
		onOverHandler(event) {
2  
simon committed
56

simon committed
57 58 59 60
			let ul = event.currentTarget.childNodes[1].childNodes[1];
			ul.style.display = "block";
		},
		onOutHandler(event) {
2  
simon committed
61
			// console.log(event);
simon committed
62 63 64
			let ul = event.currentTarget.childNodes[1].childNodes[1];
			ul.style.display = "none";
		},
2  
simon committed
65
		onClickHandler(event, index) {
simon committed
66
			// 隐藏其他
2  
simon committed
67 68 69 70 71 72
			// let path = event.path || (event.composedPath && event.composedPath()); //兼容火狐和safari
			// path[1].style.display = "none";
			if (this.$refs.ul) {
				this.$refs.ul.style.display = "none";
			}

simon committed
73 74 75 76 77 78 79 80 81
			// 选择item
			this.activeIndex = index;
			let curData = this.dataList[index];
			if (this.type == "lang") {
				// 如果是语言设置,则设置语言
				let lang = curData.value;
				this.$i18n.locale = lang;
				localStorage.setItem("lang", lang);
				this.sTitle = curData.name;
simon committed
82
				window.location.reload();
simon committed
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
			} else {
				// 不是的话,跳转页面
				this.$router.push({
					path: curData.path
				})
			}
			// console.log("name:", this.dataList[index].name);
			// this.$emit("change", {
			// 	index: index,
			// 	value: this.dataList[index]
			// });
		}
	},
	computed: {
		dplLable() {
			return this.dataList[this.activeIndex][this.labelProperty];
		}
	},
	created() {
		// this.
	},
};