Kaynağa Gözat

feat:登录功能,首页banner完成

颜琼丽 17 saat önce
ebeveyn
işleme
672d33d23d

+ 1 - 1
jd_logistics-app/api/user.js

@@ -34,7 +34,7 @@ export function userLogout(data) {
  * 根据token获取用户信息
  * 
  */
-export function getUserInfo(data) {
+export function getUserInfoApi(data) {
   return request.get('system/front/wxmini/getInfo', data);
 }
 /**

+ 1 - 1
jd_logistics-app/libs/login.js

@@ -30,7 +30,7 @@ export function checkLogin() {
   let userInfo = Cache.get(USER_INFO) ? JSON.parse(Cache.get(USER_INFO)) : null;
   let token = Cache.get(TOKEN);
   const appStore = useAppStore();
-  if (userInfo && userInfo.userPhone && token) {
+  if (userInfo && token) {
     return true;
   } else {
     Cache.clear(TOKEN);

+ 111 - 2
jd_logistics-app/pages/address/address_list.vue

@@ -1,11 +1,26 @@
 <template>
 	<view class="address-page">
 		<!-- 地址列表 -->
-		<scroll-view class="address-list" scroll-y>
+		<scroll-view class="address-list" scroll-y @scrolltolower="loadMore">
 			<!-- 地址项组件 -->
-			<address-item v-for="(item, index) in addressList" :key="item.id" :address="item"
+			<address-item v-if="addressList.length > 0" v-for="(item, index) in addressList" :key="item.id" :address="item"
 				:is-default="item.isDefault" @set-default="handleSetDefault(index)" @edit="handleEdit(index)"
 				@delete="handleDelete(index)" />
+				
+				<!-- 空状态 -->
+				<view class="empty-state" v-if="addressList.length === 0 && !loadState">
+					<u-icon class="empty-icon" name="list" size="60" color="#ccc"></u-icon>
+					<text class="empty-text">暂无数据</text>
+				</view>
+				
+				<!-- 加载状态提示 -->
+				<view class="load-more-status" v-if="loadState">
+					<text>加载中...</text>
+				</view>
+				
+				<view class="load-more-status" v-if="loadFinished && addressList.length !== 0">
+					<text>没有更多数据了</text>
+				</view>
 		</scroll-view>
 
 		<!-- 添加新地址按钮 -->
@@ -22,7 +37,16 @@
 	import {
 		ref
 	} from 'vue'
+	import { onShow } from '@dcloudio/uni-app'
 	import AddressItem from '@/components/AddressItem.vue'
+	import { listBook } from '../../api/address'
+	
+	
+	const pageNum = ref(1)
+	const pageSize = ref(10)
+	const recordTotal = ref(0)
+	const loadState = ref(false)
+	const loadFinished = ref(false)
 
 	// 模拟地址数据
 	const addressList = ref([{
@@ -99,6 +123,11 @@
 
 	// 当前要操作的地址索引
 	const currentIndex = ref(-1)
+	
+	
+	onShow(() => {
+		getAddressList(false)
+	})
 
 	// 设置默认地址
 	const handleSetDefault = (index) => {
@@ -146,6 +175,64 @@
 			url: '/pages/address/edit'
 		})
 	}
+	
+	const loadMore = () => {
+		pageNum.value++
+		getAddressList(true)
+	}
+	
+	
+	
+	// 获取收益明细列表
+	const getAddressList = (isLoadMore = false) => {
+		if (loadState.value) return
+	
+		if (!isLoadMore) {
+			pageNum.value = 1
+			loadFinished.value = false
+			addressList.value = []
+		}
+		loadState.value = true
+		//商品状态(0 待上架  1 上架  2 下架 )
+		const params = {
+			pageNum: pageNum.value,
+			pageSize: pageSize.value
+		}
+	
+		uni.showLoading({mask:true})
+		listBook(params).then(res => {
+			uni.hideLoading()
+			loadState.value = false
+			if (res.code === 200) {
+				const list = res.rows || []
+				const total = res.total || 0
+	
+	
+				if (isLoadMore) {
+					addressList.value = [...addressList.value, ...list]
+				} else {
+					addressList.value = list
+				}
+				recordTotal.value = total
+				
+				if(currentStatus.value === "1"){
+					saleTotal.value = res.total || 0
+				}else{
+					downTotal.value = res.total || 0
+				}
+				
+				// 判断是否还有更多数据
+				if (list.length < pageSize.value) {
+					loadFinished.value = true
+				}
+			}
+		}, err => {
+			loadState.value = false
+			uni.hideLoading()
+		})
+	}
+	
+	
 </script>
 
 <style scoped>
@@ -161,6 +248,28 @@
 		padding: 20rpx 30rpx;
 		box-sizing: border-box;
 	}
+	
+	.load-more-status {
+		text-align: center;
+		padding: 20rpx;
+		font-size: 24rpx;
+		color: #999;
+	}
+	
+	
+	.empty-state {
+		display: flex;
+		flex-direction: column;
+		align-items: center;
+		justify-content: center;
+		padding: 120rpx 40rpx;
+		color: #999999;
+	}
+	
+	.empty-text {
+		margin-top: 20rpx;
+		font-size: 28rpx;
+	}
 
 	.add-btn-container {
 		width: 100%;

+ 2 - 1
jd_logistics-app/pages/index/index.vue

@@ -58,6 +58,7 @@
 	import {
 		ref,onMounted
 	} from 'vue'
+	import {onShow} from '@dcloudio/uni-app'
 	// 导入 u-popup 弹框组件
 	import PersonalExpressDialog from './components/PersonalExpressDialog.vue'
 	import { bannerList } from '../../api/user'
@@ -67,7 +68,7 @@
 	// 轮播图数据
 	const swiperList = ref([])
 	
-	onMounted(()=>{
+	onShow(()=>{
 		getBannerList()
 	})
 	

+ 17 - 15
jd_logistics-app/pages/mine/mine.vue

@@ -21,8 +21,8 @@
 									<view class="user-name" @click="toUser">
 										{{ displayName }}
 									</view>
-									<view class="department-badge">
-										储运部
+									<view class="department-badge" v-if="dept">
+										{{dept}}
 									</view>
 								</view>
 								
@@ -146,9 +146,12 @@ const userAvatar = computed(() => {
 const displayName = computed(() => {
 	return appStore.userInfo?.nickName || appStore.userInfo?.userName;
 });
+const dept = computed(() => {
+	return appStore.userInfo?.dept?.deptName || "";
+});
 
 const userAccount = computed(() => {
-	return appStore.userInfo?.phonenumber || '';
+	return  appStore.userInfo?.userName || appStore.userInfo?.phonenumber || '';
 });
 
 const loginButtonText = computed(() => {
@@ -176,7 +179,7 @@ onShow(() => {
 
 // 检查用户状态
 async function checkUserStatus() {
-	if (appStore.token && !appStore.userInfo) {
+	if (appStore.token && !appStore.userName) {
 		pageLoading.value = true;
 		try {
 			await appStore.USERINFO();
@@ -264,16 +267,7 @@ async function handleGetPhoneNumber(e) {
 		await quickLogin(e, {
 			onSuccess: (result) => {
 				console.log('页面登录成功回调:', result);
-				// 页面特定的成功逻辑
-				uni.showToast({
-					title: result.message || `欢迎回来,${result.userInfo?.userName || '用户'}`,
-					icon: 'success',
-					duration: 2000
-				});
-				
-				// 由于appStore.USERINFO()已经在工具函数中调用,这里不需要再调用
-				// 但我们可以触发页面更新
-				uni.$emit('pageRefresh');
+		        appStore.UPDATE_USERINFO(result.data)
 			},
 			onFail: (error) => {
 				console.log('页面登录失败回调:', error);
@@ -422,6 +416,7 @@ function userLogoutFn() {
 					justify-content: center;
 					
 					.name-section {
+						width: 530rpx;
 						height: 52rpx;
 						display: flex;
 						align-items: center;
@@ -434,6 +429,9 @@ function userLogoutFn() {
 						color: #333333;
 						text-align: center;
 						line-height: 1;
+						white-space: nowrap; // 强制文本在一行内显示
+						overflow: hidden; // 隐藏溢出部分
+						text-overflow: ellipsis; // 用省略号代替被隐藏的文本
 					}
 
 					.login-button {
@@ -472,7 +470,6 @@ function userLogoutFn() {
 			}
 
 			.department-badge {
-				width: 104rpx;
 				background: #1B64F0;
 				border-radius: 8rpx;
 				font-size: 24rpx;
@@ -481,6 +478,11 @@ function userLogoutFn() {
 				margin-left: 8rpx;
 				padding: 7rpx 16rpx;
 				line-height: 1;
+				flex-shrink: 0;
+				max-width: 200rpx;
+				white-space: nowrap; // 强制文本在一行内显示
+				overflow: hidden; // 隐藏溢出部分
+				text-overflow: ellipsis; // 用省略号代替被隐藏的文本
 			}
 		}
 	}

+ 8 - 8
jd_logistics-app/stores/app.js

@@ -1,5 +1,5 @@
 import { defineStore } from "pinia";
-import { getUserInfo } from "@/api/user.js";
+import { getUserInfoApi } from "@/api/user.js";
 import Cache from "@/utils/cache.js";
 import { USER_INFO,CITYINFO,TOKEN} from "@/config/cache.js";
 import { uniLogin } from "@/utils/util.js";
@@ -7,12 +7,12 @@ export const useAppStore = defineStore("app", {
   state: () => {
     return {
       userInfo: Cache.get(USER_INFO) ? JSON.parse(Cache.get(USER_INFO)) : null,
-      token: Cache.get(TOKEN) || null,
+      token: Cache.get(TOKEN) || "",
       agentId: '',//当前选择的智能体ID
       useBalance:false,//是否使用晓豆
       msgContent:'',//当前跳转过来带的问题
       moneyUnit:'AI豆',//默认晓豆
-      title: "财税知识平台",//小程序名字
+      title: "瑞鲸速达",//小程序名字
       statusBarHeight: 0,//状态栏高度
       navbarHeight: 0,//导航栏总高度
       bgDefaultImage:"https://fs.bjwdys.com/miniapp/bg-default.png?time="+Date.now(),//纯色背景图,带时间戳防止缓存
@@ -21,7 +21,7 @@ export const useAppStore = defineStore("app", {
   getters: {
     $userInfo: (state) => state.userInfo,
     onShareAppMessageObj:(state) =>({
-      title: "财税知识平台",
+      title: "瑞鲸速达",
       path: `/pages/index/index?scene=inviteCode=${state.userInfo?.inviteCode || ''}`, // 分享路径
     })
   },
@@ -48,13 +48,13 @@ export const useAppStore = defineStore("app", {
     UPDATE_USERINFO(userInfo) {
       this.userInfo = userInfo;
       Cache.set(USER_INFO, userInfo);
-      uniLogin();
+      // uniLogin();
     },
     async USERINFO(force) {
       try {
-        const res = await getUserInfo();
-        this.UPDATE_USERINFO(res.data);
-        return res.data;
+        const res = await getUserInfoApi();
+        this.UPDATE_USERINFO(res.user);
+        return res.user;
       } catch (e) {
         // 可以处理异常
       }

+ 1 - 1
jd_logistics-app/utils/request.js

@@ -21,7 +21,7 @@ function baseRequest(url, method, data, {
 	const appStore = useAppStore();
   const { Toast } = useToast();
 	let Url = HTTP_REQUEST_URL,header = HEADER
-	const TOKEN = appStore.token
+	const TOKEN = 'Bearer ' + appStore.token
 	if (params != undefined) {
 		header = HEADERPARAMS;
 	}

+ 29 - 69
jd_logistics-app/utils/util.js

@@ -1,6 +1,6 @@
 import { useAppStore } from "@/stores/app";
 import { toLogin, checkLogin } from '@/libs/login'
-import { wxLogin, updateOpenId,getUserInfo } from "@/api/user.js";
+import { wxLogin, updateOpenId ,getUserInfoApi} from "@/api/user.js";
 import { useToast } from "@/hooks/useToast";
 import Cache from "./cache";
 import {
@@ -51,6 +51,11 @@ export function uniLogin() {
   }
 }
 
+export function getUserInfo (e) {
+  const appStore = useAppStore();
+  if(Cache.get(TOKEN))appStore.USERINFO();
+};
+
 /**
  * 统一登录方法:同时获取openid和手机号
  * @param {Object} e - 微信获取手机号事件对象
@@ -211,75 +216,33 @@ async function handleLoginWithPhoneCode(phoneCode, options) {
   // 5. 处理后端响应
   if (res.code === 200) {
     const appStore = useAppStore();
-    
     // 保存token
     appStore.UPDATE_TOKEN(res.data.access_token || res.data);
 
     // 获取用户信息
-    await appStore.USERINFO();
-
-    // 移除了Toast,只在页面显示
-    // 触发登录成功事件
-    uni.$emit('loginSuccess');
-
-    // 登录成功后的处理(例如跳转)
-    await handleAfterLoginSuccess(options);
-
-    return {
-      success: true,
-      data: res.data,
-      message: res.msg || '登录成功',
-      userInfo: appStore.userInfo
-    };
-  } else {
-    // 处理业务错误
-    const error = {
-      code: res.code,
-      message: res.msg || res.data?.message || '登录失败',
-      data: res.data
-    };
-    throw error;
-  }
+    const loginResult = await getUserInfoApi();
+	if(loginResult.code == 200){
+		// 移除了Toast,只在页面显示
+		// 触发登录成功事件
+		uni.$emit('loginSuccess');
+		return {
+		  success: true,
+		  data: loginResult.user,
+		  message: res.msg || '登录成功',
+		  userInfo: loginResult.user
+		};
+	}
+
+  } 
+  // 处理业务错误
+  const error = {
+    code: res.code,
+    message: res.msg || res.data?.message || '登录失败',
+    data: res.data
+  };
+  throw error;
 }
 
-/**
- * 登录成功后的处理
- */
-async function handleAfterLoginSuccess(options) {
-  try {
-    // 如果有回调URL,则跳转
-    if (options.redirectUrl) {
-      setTimeout(() => {
-        if (options.redirectUrl.startsWith('/')) {
-          uni.redirectTo({ url: options.redirectUrl });
-        } else {
-          uni.switchTab({ url: options.redirectUrl });
-        }
-      }, 1500);
-      return;
-    }
-
-    // 默认跳转逻辑
-    const pages = getCurrentPages();
-    const currentRoute = pages[pages.length - 1]?.route || '';
-
-    // 如果当前在个人中心页面,刷新页面即可
-    if (currentRoute.includes('mine')) {
-      // 可以触发页面刷新
-      const eventChannel = pages[pages.length - 1];
-      if (eventChannel && eventChannel.onLoad) {
-        eventChannel.onLoad();
-      }
-    } else {
-      // 其他页面跳转到个人中心
-      setTimeout(() => {
-        uni.switchTab({ url: '/pages/mine/mine' });
-      }, 1500);
-    }
-  } catch (error) {
-    console.error('登录后处理失败:', error);
-  }
-}
 
 /**
  * 快捷登录方法(适用于页面直接调用)
@@ -517,11 +480,8 @@ export function getSceneInfo (e) {
     return params;
   }
 };
-//获取客户信息
-export function getUserInfo (e) {
-  const appStore = useAppStore();
-  if(Cache.get(TOKEN))appStore.USERINFO();
-};
+
+
 export async function chooseImageOne(apiUrl="chat/file/imageUpload") {
   return new Promise((resolve, reject) => {
     uni.chooseImage({