Ver código fonte

登录状态监听

zhengnaiwen_citu 9 meses atrás
pai
commit
73707d011e

+ 12 - 1
components/ResumeStatus/index.vue

@@ -14,7 +14,7 @@
 </template>
 
 <script setup>
-import { ref } from 'vue';
+import { ref, watch } from 'vue';
 import { getRecommendCount } from '@/api/position.js'
 import { getDict } from '@/hooks/useDictionaries.js'
 // const props = defineProps({
@@ -24,6 +24,17 @@ import { getDict } from '@/hooks/useDictionaries.js'
 // 	}
 // })
 
+import { userStore } from '@/store/user'
+const useUserStore = userStore()
+
+watch(() => useUserStore.isLogin, (newVal, oldVal) => {
+  if (useUserStore.isLogin) {
+		// 监听登录状态
+		console.log('重新登录了')
+		recommendCount()
+	}
+})
+
 const items = ref([])
 
 const handleTo = (item) => {

+ 4 - 83
pages/index/crowdsourcing.vue

@@ -8,10 +8,6 @@
 					<text class="content-top-title-label-l">猎聘</text>
 					<text class="content-top-title-label-s">全球海量岗位 | 推荐有赏</text>
 				</view>
-				<!-- <view class="content-top-title-local" @tap="handleMap">
-					<uni-icons type="icon-map" custom-prefix="iconfont" color="#999"/>
-					{{ useUserStore.isLogin ? localtion : null }}
-				</view> -->
 			</view>
 			<view class="content-top-carousel">
 				<view class="content-top-carousel-box">
@@ -24,89 +20,24 @@
 						<template #header>
 							<view class="content-top-recommend-box-title">
 								<text class="title">我的推荐</text>
-								<!-- <view class="route">
-									<text>推荐好友入职得赏金</text>
-									<uni-icons type="icon-right" custom-prefix="iconfont" color="#999"/>
-								</view> -->
 							</view>
 						</template>
-						
 					</resume-status>
 				</view>
 			</view>
 		  </view>
 		  <view class="content-main">
-			<!-- <view class="content-main-filter">
-				<view class="content-main-filter-type">
-					<text
-						v-for="item in chooseItems"
-						:key="item"
-						class="content-main-filter-type-item"
-						:class="{ active: item === chooseItem}"
-						@tap="handleChoose(item)"
-					>{{ item}}</text>
-				</view>
-				<view class="content-main-filter-filter">
-					<text>筛选</text>
-					<uni-icons type="icon-Filter" custom-prefix="iconfont" color="#999"/>
-				</view>
-				
-			</view> -->
 			<view class="content-main-list">
 				<PositionList class="pb-10" :list="items" :noMore="items.length === total"></PositionList>
-				<!-- template v-if="items.length === 0">
-					<view class="nodata-img-parent">
-					  <image src="https://minio.citupro.com/dev/static/nodata.png" mode="widthFix" style="width: 100vw;height: 100vh;"></image>
-					</view>
-				</template>
-				<view v-for="(item,index) in items" :key="item.id" class="content-main-list-box">
-					<view class="top">
-						<view class="title">{{ item.name }}</view>
-						<text class="remuneration">
-							{{ item.payFrom }}
-							{{ item.payTo ? ' - ' : ''}}
-							{{ item.payTo }}
-							{{ item.payName }}
-						</text>
-					</view>
-					<view class="main">
-						<view class="tag blue">
-							赏 
-							<uni-icons
-								type="icon-renminbi1688"
-								size="10"
-								custom-prefix="iconfont"
-								color="royalblue"
-							/>
-							{{ item.hirePrice }}
-						</view>
-						<view v-for="tag in item.tagList" :key="tag + index" class="tag">
-							{{ tag }}
-						</view>
-					</view>
-					<view class="bottom">
-						<view class="origin">
-							<text>{{ item.anotherName }}</text>
-							<text class="interval">·</text>
-							<text>{{ item.areaName }}</text>
-						</view>
-					</view>
-				</view>
-				<template v-if="items.length === total">
-					<view class="noMore">
-						没有更多了
-					</view>
-				</template> -->
 			</view>
 		  </view>
-		<!-- <image src="https://minio.citupro.com/dev/static/nodata.png" mode="widthFix" style="width: 100vw;height: 100vh;"></image> -->
 	  </view>
 	</scroll-view>
   </layout-page>
 </template>
 
 <script setup>
-import { ref, reactive } from 'vue'
+import { ref, reactive, watch } from 'vue'
 import SwiperAd from '@/components/SwiperAd'
 import { showAuthModal } from '@/hooks/useModal'
 import { swiperAdListTest } from '@/utils/testData'
@@ -119,15 +50,7 @@ import { dealDictArrayData } from '@/utils/position.js'
 import PositionList from '@/components/PositionList'
 
 const swiperAdList = ref(swiperAdListTest)
-// const useUserStore = userStore()
-// const localtion = ref('全国')
-// const chooseItem = ref('同城')
-// const chooseItems = reactive(['同城','最新'])
-
 const items = reactive([])
-// const unitDict = ref([])
-// const areaDict = ref([])
-
 const pageInfo = ref({
 	pageNo: 1,
 	pageSize: 10
@@ -136,8 +59,10 @@ const pageInfo = ref({
 const loading = ref(false)
 const total = ref(0)
 
+
+
+
 const loadingMore = (e) => {
-	// console.log(total.value, items.length)
 	if (total.value === items.length) {
 		return
 	}
@@ -148,10 +73,6 @@ const loadingMore = (e) => {
 	getList()
 }
 
-// function handleDetails (item) {
-// 	console.log(item)
-// }
-
 async function getList () {
 	loading.value = true
 	try {

+ 13 - 1
pagesA/recommendation/index.vue

@@ -18,7 +18,7 @@
 </template>
 
 <script setup>
-import { ref } from 'vue'
+import { ref, watch } from 'vue'
 import layoutPage from '@/layout'
 
 import MList from './list'
@@ -26,6 +26,18 @@ import { getDict } from '@/hooks/useDictionaries.js'
 import { getRecommendationList } from '@/api/position.js'
 import { onLoad } from '@dcloudio/uni-app'
 
+import { userStore } from '@/store/user'
+const useUserStore = userStore()
+
+watch(() => useUserStore.isLogin, (newVal, oldVal) => {
+  if (useUserStore.isLogin) {
+		// 监听登录状态
+		console.log('重新登录了')
+		handleChange({ currentIndex: current.value })
+	}
+})
+
+
 const current = ref(0)
 
 // 获取参数

+ 3 - 0
store/user.js

@@ -39,6 +39,9 @@ export const userStore = defineStore({
   }),
 
   actions: {
+    setLogin (val) {
+      this.isLogin = val
+    },
     // 登录
     async handleSmsLogin (query, type, route) {
       const api = type ? smsLogin : passwordLogin

+ 3 - 1
utils/request.js

@@ -296,11 +296,13 @@ const handleAuthorized = () => {
 		title:'请先登录',
 		icon: 'none'
 	})
+	const msg = useUserStore.isLogin ? '您的登陆已过期' : '请先登录'
+	useUserStore.setLogin(false)
 	showAuthModal()
   // 登录超时
   return Promise.reject({
     code: 401,
-    msg: useUserStore.isLogin ? '您的登陆已过期' : '请先登录'
+    msg
   })
 }