Kaynağa Gözat

增加authLogin hook

ming 3 yıl önce
ebeveyn
işleme
cacec4b44e
2 değiştirilmiş dosya ile 28 ekleme ve 1 silme
  1. 27 0
      hooks/useAuthLogin/index.js
  2. 1 1
      utils/http.js

+ 27 - 0
hooks/useAuthLogin/index.js

@@ -0,0 +1,27 @@
+import { computed } from 'vue'
+import { useStore } from 'vuex'
+
+export default () => {
+	return cb => {
+		const store = useStore()
+		const token = computed(() => store.state.token)
+		
+		if (token.value) {
+			cb && cb()
+		} else{
+			uni.showModal({
+				content: '你还未登录,请先登录',
+				confirmText: '去登录',
+				confirmColor: '#0063F5',
+				success: function (res) {
+					if (res.confirm) {
+						uni.navigateTo({
+							url: '/modules/common/login/login'
+						})
+					}
+				}
+			})
+		}
+	}
+}
+

+ 1 - 1
utils/http.js

@@ -32,7 +32,7 @@ const request = (method, url, data, opt) => {
 			
 			if (data.code === 200 || data.success) {
 				resolve(data)
-			} else{
+			} else {
 				uni.showToast({
 					title: data.msg,
 					icon: 'none'