Prechádzať zdrojové kódy

Merge branch '2024鹅状元' of https://gogs.mtavip.com/wangguoyu/uniProject into 2024鹅状元

tanxue 5 mesiacov pred
rodič
commit
d534db1e85
4 zmenil súbory, kde vykonal 50 pridanie a 29 odobranie
  1. 7 11
      pages/login/login.vue
  2. 38 1
      pages/study/index.vue
  3. 1 11
      utils/cacheManager.js
  4. 4 6
      utils/request.js

+ 7 - 11
pages/login/login.vue

@@ -32,9 +32,7 @@
 		sendCode
 	} from "@/api/login.js"
 	import sliderDialog from './sliderDialog.vue'
-	import {
-		getAuth
-	} from '@/utils/auth.js';
+	import cacheManager from '@/utils/cacheManager.js';
 	export default {
 		data() {
 			return {
@@ -91,19 +89,17 @@
 					code: this.loginData.yzmNumber,
 				}
 				login(req).then(res => {
-					if (res.code == 0) {
-						let obj = JSON.stringify(res.data)
-						uni.setStorage({
-							key: 'Mta-Auth',
-							data: obj // 假设 this.userInputValue 是用户输入的数据
-						});
-						if (res.data.nianji == 0 && res.data.xueqi == 0 ) {
+					if (res.code == 0) {
+						// 暂时写死
+						res.data.cardId = 1
+						cacheManager.set('auth',res.data)
+						if (res.data.nianji == 0 && res.data.cardId == 0 ) {
 							uni.redirectTo({
 								url: `/pages/selectGradesTerms/index`
 							})
 						} else {
 							uni.redirectTo({
-								url: `/pages/study/index?nianji=${res.data.nianji}&xueqi=${res.data.xueqi}&zhangId=${JSON.parse(getAuth()).userId}`
+								url: `/pages/study/index?nianji=${res.data.nianji}&cardId=${res.data.cardId}&zhangId=${cacheManager.get('auth').zhangId}`
 							})
 						}
 					}

+ 38 - 1
pages/study/index.vue

@@ -1,7 +1,7 @@
 <template>
 	<view class="ezy-study-page">
 		<view class="study-school-year" @click="clickGradeTerm">{{gradeTerm}}</view>
-		<view class="ezy-study-wrap">
+		<view class="ezy-study-wrap" @touchstart="onTouchStart" @touchend="onTouchEnd">
 			<view class="chapter-box" @click="handleCheckCatalogue">{{infoData.numberStr}}</view>
 			<view class="chapter-title-box">{{infoData.zhangName}}</view>
 			<view>
@@ -73,6 +73,9 @@
 
 	const catalogueRef = ref(null);
 	let gradeTerm = ref('');
+	let startX = ref(0);
+	let isSliding = ref(false);
+	let endX = ref(0);
 	const selectZhang = ref(null);
 	let infoData = reactive({
 		jieList: [],
@@ -163,6 +166,40 @@
 	}
 
 
+	function onTouchStart(event) {
+		console.log(event.touches.length);
+		isSliding.value = false
+		if (event.touches.length === 1) {
+			isSliding.value = true;
+			startX.value = event.touches[0].pageX;
+		} else {
+			isSliding.value = false;
+			event.preventDefault()
+			return
+		}
+	}
+	function onSwipeLeft(event) {
+		console.log('用户左滑了');
+	}
+	function onSwipeRight(event) {
+		console.log('用户又滑了');
+	}
+	function onTouchEnd(event) {
+		if (isSliding.value) {
+			const distanceX = event.changedTouches[0].clientX - startX.value
+			if (distanceX > 0) {
+				onSwipeLeft();
+			} else if (distanceX < 0) {
+				onSwipeRight();
+			}
+			isSliding.value = false
+		}else{
+			console.log(11111);
+		}
+	}
+
+
+
 	function recordZhangJie() {
 		let req = {
 			nianji: routeParams.value.nianji,

+ 1 - 11
utils/cacheManager.js

@@ -1,8 +1,5 @@
 const cacheManager = (function() {
-	// 默认存储的前缀,可以根据需要修改
 	const STORAGE_PREFIX = 'App_cache_';
-
-	// 设置缓存
 	function set(key, value) {
 		const fullKey = STORAGE_PREFIX + key;
 		if (typeof value === 'object' && value !== null) {
@@ -18,10 +15,8 @@ const cacheManager = (function() {
 		const fullKey = STORAGE_PREFIX + key;
 		const value = uni.getStorageSync(fullKey);
 		try {
-			// 尝试将字符串解析为对象
 			return JSON.parse(value);
 		} catch (e) {
-			// 如果解析失败,则直接返回值
 			return value;
 		}
 	}
@@ -32,7 +27,6 @@ const cacheManager = (function() {
 		uni.removeStorageSync(fullKey);
 	}
 
-	// 增量修改对象中的参数或添加新参数 删除参数
 	//例子: cacheManager.updateObject('user', { www: undefined }); //删除
 	function updateObject(key, updates) {
 		let obj = get(key) || {};
@@ -43,15 +37,11 @@ const cacheManager = (function() {
 		      // 如果值为 null 或 undefined,则删除属性
 		      delete obj[keyToUpdate];
 		    } else {
-		      // 否则,更新或添加属性
 		      obj[keyToUpdate] = value;
 		    }
 		  }
-		// 重新设置缓存
 		set(key, obj);
 	}
-
-	// 清除所有以特定前缀开头的缓存
 	function clearAll() {
 		const keys = uni.getStorageInfoSync().keys;
 		keys.forEach(key => {
@@ -75,7 +65,7 @@ const cacheManager = (function() {
 			// 重新设置缓存
 			set(key, obj);
 		} else {
-			console.error(`Path ${arrayPath} does not point to an array in the object.`);
+			console.error(`${arrayPath}不指向对象中的数组。`);
 		}
 	}
 	//  例子

+ 4 - 6
utils/request.js

@@ -1,8 +1,6 @@
 //import store from '@/store'
 import config from '../config.js'
-import {
-	getAuth
-} from '@/utils/auth'
+import cacheManager from '@/utils/cacheManager.js'
 import {
 	Md5
 } from 'ts-md5/dist/md5';
@@ -26,9 +24,9 @@ const request = config => {
 	// config.headers['X-AUTH-SIGN'] = Md5.hashStr(JSON.stringify(config.data) +auth.secret);
 	// config.headers['X-AUTH-TOKEN'] = auth.token;
 	//  }
-	if (getAuth()) {
-		config.headers['X-AUTH-SIGN'] = Md5.hashStr(JSON.stringify(config.data) + JSON.parse(getAuth()).secret);
-		config.headers['X-AUTH-TOKEN'] = JSON.parse(getAuth()).token;
+	if (cacheManager.get('auth')) {
+		config.headers['X-AUTH-SIGN'] = Md5.hashStr(JSON.stringify(config.data) + cacheManager.get('auth').secret);
+		config.headers['X-AUTH-TOKEN'] =cacheManager.get('auth').token;
 	}
 	return new Promise((resolve, reject) => {
 		//  debugger