소스 검색

feat(avatar): 新增头像修改
fix(message): 修复一键已读后接收到新未读消息时按钮失效

HMY 1 년 전
부모
커밋
5cf55b6353
8개의 변경된 파일230개의 추가작업 그리고 58개의 파일을 삭제
  1. 1 3
      api/message.js
  2. 33 5
      api/mine.js
  3. 7 0
      pages.json
  4. 55 41
      pages/message/index.vue
  5. 112 0
      pages/mine/avatar/avatar.vue
  6. 5 1
      pages/mine/index.vue
  7. 1 1
      utils/request.js
  8. 16 7
      utils/upload.js

+ 1 - 3
api/message.js

@@ -88,8 +88,6 @@ export function setMsgIsRead(universalids) {
 	return request({
 		url: '/readMsgs.do?universalids=' + universalids,
 		method: 'post',
-		header: {
-			'Cookie': 'JSESSIONID=' + getSession() // 设置请求头中的Cookie字段
-		}
+		isSession: true,
 	})
 }

+ 33 - 5
api/mine.js

@@ -1,5 +1,9 @@
 import request from '@/utils/request.js'
 import config from '@/config'
+import upload from '@/utils/upload'
+import {
+	getSession
+} from '@/utils/auth.js'
 const preUrl = '/clientServices.do?iscrypt=1'
 
 export function getUserInfo(useId) {
@@ -16,10 +20,7 @@ export function getUserInfo(useId) {
 }
 
 //检查今日考勤状况
-export function checkAttendance({
-	universalid,
-	rizi
-}) {
+export function checkAttendance({universalid,rizi}) {
 	return request({
 		url: preUrl,
 		method: 'post',
@@ -94,6 +95,7 @@ export function modifyMe(params) {
 	})
 }
 
+//修改密码
 export function changePWD(params) {
 	return request({
 		url: preUrl,
@@ -126,4 +128,30 @@ export function getMyQDQtAttendance(params) {
 			}
 		}
 	})
-}
+}
+
+//头像文件上传
+export function uploadAvatarFile(data) {
+	return upload({
+    url: '/MiniAppUploadAvatarAction.do',
+    name: data.name,
+    filePath: data.filePath,
+	isSession:true,
+  })
+}
+
+//个人信息头像路径修改
+export function updateUserInfoHeaderFileId(params) {
+	return request({
+		url: preUrl,
+		method: 'post',
+		data: {
+			serviceId: 'ygoa_miniapp_updateUserInfoPhoto',
+			params: {
+				userid: params.userid,
+				headerFileId: params.headerFileId
+			}
+		}
+	})
+}
+

+ 7 - 0
pages.json

@@ -151,6 +151,13 @@
 			{
 				"navigationBarTitleText" : "AI客服"
 			}
+		},
+		{
+			"path" : "pages/mine/avatar/avatar",
+			"style" : 
+			{
+				"navigationBarTitleText" : "头像修改"
+			}
 		}
 	],
 	"tabBar": {

+ 55 - 41
pages/message/index.vue

@@ -28,10 +28,10 @@
 			title="公告"></message-list>
 
 		<!-- 消息列表 -->
-		<message-list ref="msgListRef" @readMsg="setMsgRead" :unReadNum="unReadNum" :list="messages" @clickSegment="getMessageData"
-			@clickItem="handleToMessageDetail" @scrollToBottom="getMessagePage" :defaultCurrent="1" :pSize="5"
-			:pageNo="1" :anime="true" :open="true" :segments="{ '全部': '', '未读': '0', '已读': '1' }"
-			title="消息"></message-list>
+		<message-list ref="msgListRef" @readMsg="setMsgRead" :unReadNum="unReadNum" :list="messages"
+			@clickSegment="getMessageData" @clickItem="handleToMessageDetail" @scrollToBottom="getMessagePage"
+			:defaultCurrent="1" :pSize="5" :pageNo="1" :anime="true" :open="true"
+			:segments="{ '全部': '', '未读': '0', '已读': '1' }" title="消息"></message-list>
 
 		<!-- AI咨询按钮 -->
 		<view class="fab_button">
@@ -43,7 +43,7 @@
 </template>
 
 <script setup lang="ts">
-	import { onBeforeMount, onMounted, ref } from 'vue';
+	import { onBeforeMount, onMounted, onUpdated, ref } from 'vue';
 	import { onLoad } from '@dcloudio/uni-app'
 	import { getMessageList, getNoticeList, getUnReadMessageNum, setMsgIsRead } from '@/api/message.js';
 	import { getUserProcess, getUnProcessNum } from '@/api/process';
@@ -52,18 +52,19 @@
 	import processList from '@/components/ygoa/processList.vue'
 	import messageList from '@/components/ygoa/messageList.vue'
 	import { useUserStore } from '@/store/user.js'
+	import { showConfirm } from '@/utils/common';
 	const userStore = useUserStore()
 
 	onLoad((options) => {
 		// 是否跳转打卡页
 		if (options.to == 'clockIn') toClockIn()
 	})
-	onBeforeMount(()=>{
-		
-	})
-	onMounted(() => {
+	onUpdated(()=>{
 		showTarBarBadge();
 	})
+	// onMounted(() => {
+	// 	showTarBarBadge();
+	// })
 	// 跳转打卡页
 	function toClockIn() {
 		// 确认是否跳转打卡页
@@ -72,41 +73,54 @@
 		})
 	}
 
-//子组件
-	const msgListRef=ref(null)
+	//子组件
+	const msgListRef = ref(null)
 	//设置消息已读
 	function setMsgRead() {
-		const params = {
-			currentUser: userStore.user.useId,
-			isRead: "0",
-			pSize: unReadNum.value,
-			type: "",
-			p: 1,
-		}
-		getMessageList(params).then(({ returnParams }) => {
-			const unReadMsgIds= returnParams.ids === "" ? "" : returnParams.ids + ",";
-			setMsgIsRead(unReadMsgIds).then((res) => {
-				if (Number.isInteger(res)) {
-					switch (res) {
-						case -1:
-							$modal.msgError('操作失败')
-							break
-						case -2:
-						case 0:
-							$modal.msg('不存在未读消息')
-							break
-						default:
-							$modal.msgSuccess('操作成功')
-							//刷新页面
-							msgListRef.value.reload();// 调用子组件刷新数据
-							showTarBarBadge();
-					}
-				} else {
-					$modal.msgError('jssesionid失效')
+		$modal.confirm('是否一键已读').then(res => {
+			if (res) {
+				const params = {
+					currentUser: userStore.user.useId,
+					isRead: "0",
+					pSize: unReadNum.value,
+					type: "",
+					p: 1,
 				}
-			})
+				getMessageList(params).then(({ returnParams }) => {
+					const unReadMsgIds = returnParams.ids === "" ? "" : returnParams.ids + ",";
+					setMsgIsRead(unReadMsgIds).then((res) => {
+						if (Number.isInteger(res)) {
+							switch (res) {
+								case -1:
+									$modal.msgError('操作失败')
+									break
+								case -2:
+								case 0:
+									$modal.msg('不存在未读消息')
+									break
+								default:
+									$modal.msgSuccess('操作成功')
+									//刷新页面
+									msgListRef.value.reload();// 调用子组件刷新数据
+									// showTarBarBadge();
+							}
+						} else {
+							// $modal.msgError('jssesionid失效')
+							showConfirm('jssesionid失效,您可以继续留在该页面,或者重新登录?').then(res => {
+								if (res.confirm) {
+									userStore.LogOut().then(res => {
+										uni.reLaunch({ url: '/pages/login' })
+									})
+								}
+							})
+
+						}
+					})
+				})
+			}
 		})
-		
+
+
 	}
 
 	// 待办列表
@@ -250,7 +264,7 @@
 	function showTarBarBadge() {
 		getUnProcessNum(userStore.user.useId, "").then(res => {
 			if ("failed" == res.returnMsg) {
-				$modal.msgError('待办流程数获取失败')
+				$modal.showToast('待办流程数获取失败')
 				return
 			} else {
 				unProcessNum.value = parseInt(res.returnParams.total, 10);

+ 112 - 0
pages/mine/avatar/avatar.vue

@@ -0,0 +1,112 @@
+<template>
+	<view class="container">
+		<view class="image-cropper">
+			<image :src="selectedImage.path" mode="aspectFill"></image>
+			<!-- <image src="@/static/images/mine/headImg.jpg"></image> -->
+		</view>
+
+		<button type="default" @click="chooseImage">选择头像</button>
+		<button type="primary" @click="submitImage">提交</button>
+	</view>
+</template>
+
+<script setup>
+	import {onMounted, ref} from 'vue';
+	import headImg from "@/static/images/mine/headImg.jpg"
+	import {uploadAvatarFile,updateUserInfoHeaderFileId} from '@/api/mine';
+	import { useUserStore } from '@/store/user.js';
+	import $modal from '@/plugins/modal.js';
+	import $tab from '@/plugins/tab.js'
+	import config from '@/config';
+	const userStore=useUserStore();
+	//所选头像信息
+	const selectedImage = ref({});
+
+	onMounted(()=>{
+		selectedImage.value={
+			path:headImg
+		}
+	})
+	function chooseImage() {
+		
+		let chooseFile = uni.chooseFile;
+		if (typeof wx !== 'undefined' && typeof wx.chooseMessageFile === 'function') {
+			//切换微信小程序选择文件的方法
+			chooseFile = wx.chooseMessageFile;
+		}
+		if (typeof chooseFile !== 'function') {
+			return reject({
+				errMsg: ERR_MSG_FAIL + ' 请指定 type 类型,该平台仅支持选择 image 或 video。',
+			});
+		}
+		chooseFile({
+			count: 1,
+			type: 'image',
+			success: (res) => {
+				selectedImage.value = res.tempFiles[0];
+			}
+		});
+	};
+
+	const submitImage = () => {
+		if (!selectedImage.value) return;
+		const data = {
+			name: selectedImage.value.name,
+			filePath: selectedImage.value.path
+		}
+		uploadAvatarFile(data).then(res => {
+			if('success'===res.returnMsg){
+				const params={
+					userid:userStore.useId,
+					headerFileId:res.returnParams
+				}
+				updateUserInfoHeaderFileId(params).then(res=>{
+					if('success'===res.returnMsg){
+						$modal.msgSuccess('提交成功');
+						setTimeout(() => {
+							$tab.navigateBack()
+						}, 1000);
+					}
+				})
+			}
+			
+		}).catch(err => {
+			$modal.msgError('文件' + data.name + '上传失败,请重新上传')
+			switch (err) {
+				case -201:
+					console.log('文件上传失败 未找到该文件');
+					break;
+				case -20201:
+					console.log('文件上传失败 返回值不是JSON字符串');
+					break;
+			}
+			
+		})
+
+		
+	};
+</script>
+
+<style>
+	.container {
+		display: flex;
+		flex-direction: column;
+		align-items: center;
+		padding: 20px;
+		box-sizing: border-box;
+		height: 100vh;
+		background-color: #f5f5f5;
+	}
+
+	.image-cropper image {
+		width: 200px;
+		height: 200px;
+		border-radius: 50%;
+		margin-bottom: 30px;
+	}
+
+	button {
+		margin-top: 10px;
+		width: 90%;
+	}
+</style>

+ 5 - 1
pages/mine/index.vue

@@ -3,7 +3,7 @@
 		<!-- 用户信息部分 -->
 		<uni-card margin="0" spacing="0">
 			<view class="headImg">
-				<image :src="headImg" class="avatar"></image>
+				<image :src="headImg" class="avatar" @click="toEditAvatar"></image>
 			</view>
 			<view class="user-info">
 				<view class="info-detail">
@@ -88,6 +88,7 @@
 	onMounted(() => {
 		userInfo.value = userStore.user
 		showTarBarBadge();
+		
 	})
 	
 	function showTarBarBadge(){
@@ -160,6 +161,9 @@
 	function clockIn() {
 		$tab.navigateTo('/pages/mine/clockIn/clockIn')
 	};
+	function toEditAvatar(){
+		$tab.navigateTo('/pages/mine/avatar/avatar')
+	}
 </script>
 
 

+ 1 - 1
utils/request.js

@@ -13,7 +13,7 @@ const request = config => {
   config.header = config.header || {}
   if (isSession) {
     if (getSession()) {
-      config.header['cookie'] = getSession()
+      config.header['cookie'] = 'JSESSIONID=' + getSession()
     } else {
       showConfirm('登录状态已过期,您可以继续留在该页面,或者重新登录?')
         .then(() => {

+ 16 - 7
utils/upload.js

@@ -1,6 +1,6 @@
 // import store from '@/store'
 import config from '@/config'
-// import { getToken } from '@/utils/auth'
+import { getSession } from '@/utils/auth'
 import errorCode from '@/utils/errorCode'
 import { toast, showConfirm, tansParams } from '@/utils/common'
 
@@ -8,12 +8,21 @@ let timeout = config.timeout
 const baseUrl = config.baseUrl
 
 const upload = config => {
-  // 是否需要设置 token
-  // const isToken = (config.headers || {}).isToken === false
-  config.header = config.header || {}
-  // if (getToken() && !isToken) {
-  //   config.header['Authorization'] = 'Bearer ' + getToken()
-  // }
+	const isSession = config.isSession || false
+	config.header = config.header || {}
+	if (isSession) {
+	  if (getSession()) {
+	    config.header['cookie'] = 'JSESSIONID=' + getSession()
+	  } else {
+	    showConfirm('登录状态已过期,您可以继续留在该页面,或者重新登录?')
+	      .then(() => {
+	        uni.reLaunch({ url: '/pages/login' })
+	      })
+	      .catch(() => {
+	        return
+	      })
+	  }
+	}
   // get请求映射params参数
   if (config.params) {
     let url = config.url + '?' + tansParams(config.params)