From 161501137592266c9e3add4246df31a33a29ec9a Mon Sep 17 00:00:00 2001 From: fanzhen123 <1575502816@qq.com> Date: Fri, 27 Dec 2019 11:55:33 +0800 Subject: [PATCH] fanzhen1227 --- src/components/nav/Nav.vue | 85 ++++++++++++++++----- src/main.js | 33 +------- src/router.js | 21 +++-- src/store.js | 4 + src/views/datasweb/Datasweb.vue | 11 +-- src/views/index/Index.vue | 4 + src/views/personalCenter/PersonalCenter.vue | 30 +++++--- 7 files changed, 116 insertions(+), 72 deletions(-) diff --git a/src/components/nav/Nav.vue b/src/components/nav/Nav.vue index 99d5eec..5dcbd26 100644 --- a/src/components/nav/Nav.vue +++ b/src/components/nav/Nav.vue @@ -24,11 +24,15 @@
-
登录
+
登录
@@ -181,6 +185,7 @@ export default { }) // alert('验证码输入不正确请重新输入!') } else { + let that = this // 调接口判断密码是否输入正确,改变登录状态 this.$axios({ method: 'POST', @@ -192,10 +197,6 @@ export default { }).then(res => { console.log(res) // 请求接口完成注册 请求成功 - this.$alert(res.data.message, '温馨提示', { - confirmButtonText: '确定' - }) - // alert(res.data.message) if (res.data.code === 200) { this.showWinStatic = !this.showWinStatic this.$auth.auth = this.showWinStatic @@ -205,18 +206,26 @@ export default { localStorage.setItem('userPwd', this.userpwd) localStorage.setItem('token', 'Bearer ' + res.data.data.token) localStorage.setItem('tokenB', res.data.data.token) - setTimeout(() => { - localStorage.clear() - this.$router.go(0) - }, 7200000) - // 登录状态 - localStorage.setItem('userLogin', true) - console.log(this.$route, '000111') - if (this.$route.path === '/') { - this.$router.go(0) - } else { - this.$router.push({ path: '/' }) - } + this.$alert(res.data.message, '温馨提示', { + confirmButtonText: '确定', + callback: res => { + console.log(10000) + that.userLogin = localStorage.getItem('userLogin') + that.userName = localStorage.getItem('username') + that.userPic = localStorage.getItem('pic') + // 登录状态 + localStorage.setItem('userLogin', true) + // 普通登陆状态 + this.$store.state.normalLogin = true + if (this.$route.path !== '/') { + this.$router.push({ path: '/' }) + } + setTimeout(() => { + localStorage.clear() + this.$router.go(0) + }, 7200000) + } + }) } }).catch((fail) => { console.log(fail) @@ -314,10 +323,44 @@ export default { computed: { }, mounted () { + // IP端 + this.$axios({ + method: 'GET', + url: 'site/check', + params: {} + }).then(res => { + console.log(res, 'IP段') + if (res.data.code === 200) { + this.$store.state.normalLogin = false + // 用户信息存本地 + localStorage.setItem('username', res.data.data.username) + localStorage.setItem('pic', res.data.data.pic) + localStorage.setItem('userPwd', '123456') + localStorage.setItem('token', 'Bearer ' + res.data.data.token) + localStorage.setItem('tokenB', res.data.data.token) + setTimeout(() => { + localStorage.clear() + location.reload() + }, 7200000) + // 登录状态 + localStorage.setItem('userLogin', false) + this.$auth = true + this.$store.state.ipLogin = true + } else { + if (this.$store.state.ipLogin) { + localStorage.clear() + this.$store.state.ipLogin = false + } + } + this.userLogin = localStorage.getItem('userLogin') + this.userName = localStorage.getItem('username') + this.userPic = localStorage.getItem('pic') + this.$store.state.normalLogin = this.userLogin + // 请求接口完成 请求成功 + }).catch((fail) => { + console.log(fail) + }) let that = this - this.userLogin = localStorage.getItem('userLogin') - this.userName = localStorage.getItem('username') - this.userPic = localStorage.getItem('pic') // 监听对象的变化 /* eslint-disable */ Object.defineProperty(this.$auth, 'auth', { diff --git a/src/main.js b/src/main.js index 74fbe83..8063c20 100644 --- a/src/main.js +++ b/src/main.js @@ -82,35 +82,6 @@ axios.interceptors.response.use(data => { // } return data }) -// IP端 -axios({ - method: 'GET', - url: 'site/check', - params: {} -}).then(res => { - // console.log(res, 'IP段') - if (res.data.code === 200) { - if (!localStorage.getItem('userLogin')) { - history.go(0) - } - // 用户信息存本地 - localStorage.setItem('username', res.data.data.username) - localStorage.setItem('pic', res.data.data.pic) - localStorage.setItem('userPwd', '123456') - localStorage.setItem('token', 'Bearer ' + res.data.data.token) - localStorage.setItem('tokenB', res.data.data.token) - setTimeout(() => { - localStorage.clear() - this.$router.go(0) - }, 7200000) - // 登录状态 - localStorage.setItem('userLogin', true) - Vue.prototype.$auth = true - } - // 请求接口完成 请求成功 -}).catch((fail) => { - console.log(fail) -}) // 将图形验证码写入 Vue.prototype.$identify = identify.default Vue.prototype.$axios = axios @@ -124,6 +95,10 @@ Vue.prototype.$auth = { Vue.use(VueAwesomeSwiper) Vue.use(ElementUI) +// 关闭浏览器 +window.addEventListener('beforeunload', e => { + window.localStorage.clear() +}) Vue.config.productionTip = false new Vue({ diff --git a/src/router.js b/src/router.js index ad2f0ed..68c0837 100644 --- a/src/router.js +++ b/src/router.js @@ -107,17 +107,28 @@ let RouterObj = new Router({ }) RouterObj.beforeEach((to, from, next) => { console.log(to, 'to') + console.log(from, 'from') if (to.name === 'personalCenter' || to.name === 'datasweb') { console.log(localStorage.getItem('token'), 'localStorage.getItem()') if (!localStorage.getItem('token')) { // alert('您没有该账号的登陆权限,请重新登录后再次操作!') - this.$alert('您没有该账号的登陆权限,请重新登录后再次操作!', '温馨提示', { - confirmButtonText: '确定' + Vue.prototype.$alert('您没有该账号的登陆权限,请重新登录后再次操作!', '温馨提示', { + confirmButtonText: '确定', + callback: res => { + console.log(Vue.prototype.$auth, 'Vue.prototype.$auth') + Vue.prototype.$auth.auth = true + console.log(Vue.prototype.$auth, 'Vue.prototype.$auth') + if (from.name !== 'index') { + next({ + name: 'index', + params: { + type: 'loginTrue' + } + }) + } + } }) // 权限通过时赋值 - console.log(Vue.prototype.$auth, 'Vue.prototype.$auth') - Vue.prototype.$auth.auth = true - console.log(Vue.prototype.$auth, 'Vue.prototype.$auth') // localStorage.clear() // window.location.reload() } else { diff --git a/src/store.js b/src/store.js index 5a8a6c4..985d917 100644 --- a/src/store.js +++ b/src/store.js @@ -5,6 +5,10 @@ Vue.use(Vuex) export default new Vuex.Store({ state: { + // ip登陆状态 + ipLogin: false, + // 平常登录状态 + normalLogin: false, // 定义一个窗口状态(新增指标) insertWindowState: false, // 定义一个筛选窗口状态 diff --git a/src/views/datasweb/Datasweb.vue b/src/views/datasweb/Datasweb.vue index d20fccf..5174b1f 100644 --- a/src/views/datasweb/Datasweb.vue +++ b/src/views/datasweb/Datasweb.vue @@ -574,23 +574,24 @@ export default { let that = this switch (ind) { case 0: - this.cutStateSeach = 'simpleness' this.$store.state.advancedSearchState = false + this.cutStateSeach = 'simpleness' + this.$router.go(0) break case 1: - this.cutStateSeach = 'advanced' this.$store.state.advancedSearchState = true + this.cutStateSeach = 'advanced' break case 2: if (this.$route.query.type === 'area') { this.cutStateSeach = 'map' } else { + this.$store.state.advancedSearchState = false // alert('地图功能对非地区数据无效!') this.$alert('地图功能对非地区数据无效!', '温馨提示', { confirmButtonText: '确定' }) } - this.$store.state.advancedSearchState = false break case 3:// 添加收藏 this.$store.state.addCollectState = true @@ -634,9 +635,9 @@ export default { case 'search':// 调接进行高级查询 // 调用接口查询高级查询的数据 console.log(this.$store.state.advanceData) - if (this.$store.state.advanceData.length < 4) { + if (this.$store.state.advanceData.length < 1) { // alert('筛选数据数据不能少于4条!') - this.$alert('筛选数据数据不能少于4条!', '温馨提示', { + this.$alert('筛选数据数据不能少于1条!', '温馨提示', { confirmButtonText: '确定' }) return diff --git a/src/views/index/Index.vue b/src/views/index/Index.vue index b28dee6..4ea3de1 100644 --- a/src/views/index/Index.vue +++ b/src/views/index/Index.vue @@ -660,6 +660,10 @@ export default { this.dataUpdating() // 24小时热闻 this.hotArticle() + if (this.$route.params.type === 'loginTrue') { + console.log(this.$route.params.type, 'this.$router.query.type ') + this.$auth.auth = true + } } } diff --git a/src/views/personalCenter/PersonalCenter.vue b/src/views/personalCenter/PersonalCenter.vue index 4ca2c5e..45b8d13 100644 --- a/src/views/personalCenter/PersonalCenter.vue +++ b/src/views/personalCenter/PersonalCenter.vue @@ -5,7 +5,7 @@
-
+
个人中心
@@ -25,7 +25,7 @@
{{staticSelect}}
-
+
搜索
@@ -50,7 +50,7 @@
-
+
名称
@@ -92,10 +92,7 @@ @current-change="currentChange" >
-
{{!collect?collect.length!==0?'':'暂无收藏记录':'加载中...'}}
+
暂无收藏记录
@@ -218,7 +215,7 @@ export default { // // staticInput: false // // } // ], - collect: null, + collect: [], // 我的收藏名称 collectName: '', // 分页配置 @@ -380,7 +377,8 @@ export default { id: item.id, classify_id: item.classify_id, type: item.type, - uid: item.uid + uid: item.uid, + f: item.f } }) } @@ -441,13 +439,19 @@ export default { // 跳转至查询页面 jumpSearch (listCount) { console.log(listCount) - this.$route.push( + this.$router.push( { path: '/datasweb', - type: listCount.f, - defaultLeftId: listCount.classify_id + query: { + type: listCount.f, + defaultLeftId: listCount.classify_id + } } ) + }, + // 页面刷新跳转 + beforeunloadEv () { + this.$router.push({ path: '/' }) } }, // 自定义指令v-* @@ -465,6 +469,7 @@ export default { // 计算字符串 computedStr () { return (str) => { + console.log(str, 'str10123') let Strs = '' str.length <= 62 ? (Strs = str) : (Strs = str.slice(0, 61) + '...') return Strs @@ -473,6 +478,7 @@ export default { }, mounted () { this.getPersonalCenter(1) + window.onbeforeunload = this.beforeunloadEv() } }