xiaohaizhao 3 miesięcy temu
rodzic
commit
c1ddc4f21a
4 zmienionych plików z 199 dodań i 49 usunięć
  1. 18 7
      App.vue
  2. 23 7
      components/My_upload/My_upload.vue
  3. 146 16
      pages/index/my.vue
  4. 12 19
      utils/Http.js

+ 18 - 7
App.vue

@@ -6,15 +6,28 @@ export default {
 		if (uni.getStorageSync('userMsg').token) {
 			{
 				$Http.basic({
-					"id": "2025082114391803",
-					"content": {
-						"phonenumber": uni.getStorageSync('userMsg').phonenumber
+					"classname": "webmanage.site.site",
+					"method": "querySite_Parameter", //查询站点数据
+					content: {
+						nocache: true
 					}
 				}).then(res => {
 					if (res.code == 1) {
-						uni.removeStorageSync('userRecord');
-						uni.setStorageSync("userRecord", res.data)
+						uni.removeStorageSync('siteP');
+						uni.setStorageSync("siteP", res.data)
 						$Http.isLoad = true;
+
+						$Http.basic({
+							"id": "2025082114391803",
+							"content": {
+								"phonenumber": uni.getStorageSync('userMsg').phonenumber
+							}
+						}).then(res => {
+							if (res.code == 1) {
+								uni.removeStorageSync('userRecord');
+								uni.setStorageSync("userRecord", res.data)
+							}
+						})
 					} else {
 						$Http.isLoad = false;
 					}
@@ -44,6 +57,4 @@ page {
 	background-color: rgba(0, 0, 0, 0.1) !important;
 	opacity: 0.7 !important;
 }
-
-
 </style>

+ 23 - 7
components/My_upload/My_upload.vue

@@ -1,11 +1,17 @@
 <template>
-    <up-upload :fileList="fileList" @after-read="afterRead" :deletable="!disabled" @delete="deletePic"
+    <view v-if="custom">
+        <up-upload @after-read="afterRead" :deletable="!disabled" @delete="deletePic"
+            :max-count="disabled ? fileList.length : maxCount" :accept="accept" multiple @clickPreview="clickPreview">
+            <slot />
+        </up-upload>
+    </view>
+    <up-upload v-else :fileList="fileList" @after-read="afterRead" :deletable="!disabled" @delete="deletePic"
         :max-count="disabled ? fileList.length : maxCount" :accept="accept" multiple @clickPreview="clickPreview" />
 </template>
 
 <script setup>
 import { ref, reactive, defineProps, defineEmits, getCurrentInstance, onUnmounted } from 'vue'
-const emit = defineEmits(['uploadCallback'])
+const emit = defineEmits(['uploadCallback', 'startUploading'])
 const props = defineProps({
     accept: {
         type: String,
@@ -18,6 +24,9 @@ const props = defineProps({
     uploadCallback: {
         type: Function
     },
+    startUploading: {
+        type: Function
+    },
     fileList: {
         type: Array,
         default: reactive([])
@@ -37,6 +46,10 @@ const props = defineProps({
     disabled: {
         type: Boolean,
         default: false
+    },
+    custom: {
+        type: Boolean,
+        default: false
     }
 })
 const { $Http } = getCurrentInstance().proxy;
@@ -52,17 +65,18 @@ const clickPreview = (e) => {
 
 // 文件读取后处理
 const afterRead = ({ file }) => {
+    emit('startUploading', file);
     file.forEach(v => {
         // #ifdef H5
         getArrayBuffer(v).then(data => {
             data.data.url = v.url;
+            console.log("data.data", data.data)
             handleUploadFile(requestType(v), data.data)
             props.fileList.push({
                 ...v,
                 status: 'uploading',
                 message: '上传中',
             });
-
         })
         // #endif
 
@@ -136,11 +150,13 @@ const getArrayBuffer = (file) => {
                 const files = new File(
                     [myBlob],
                     file.name,
-                    { type: file.type }
+                    { type: file.type },
                 )
                 const reader = new FileReader()
                 reader.readAsArrayBuffer(files)
-                reader.onload = () => resolve(reader.result)
+                reader.onload = () => resolve({
+                    data: reader.result
+                })
                 reader.onerror = error => reject(error)
             } else {
                 reject(`文件加载失败: ${this.status}`)
@@ -152,7 +168,6 @@ const getArrayBuffer = (file) => {
 }
 
 // 上传文件到服务器
-
 const uploadFile = (res, data) => {
     uni.request({
         url: res.uploadurl,
@@ -225,6 +240,7 @@ const saveFileLinks = (ownertable, ownerid, usetype = 'default') => {
     deleteList.length && deleteFile(deleteList);
     return new Promise((resolve, reject) => {
         const list = props.fileList;
+        console.log("list", list)
         if (list.length) {
             return handleFileLink(list, ownertable, ownerid, usetype, resolve);
         } else {
@@ -304,5 +320,5 @@ onUnmounted(() => {
     clearTemporaryFiles();
 })
 
-defineExpose({ isUploading, saveFileLinks })
+defineExpose({ isUploading, handleFileLink, saveFileLinks, deleteFile })
 </script>

+ 146 - 16
pages/index/my.vue

@@ -1,5 +1,5 @@
 <template>
-	<view class="user" hover-class="navigator-hover">
+	<view class="user" hover-class="navigator-hover" @click="popupShow = true">
 		<view class="profile-photo">
 			<up-image :show-loading="true" :src="user.profilePhoto" width="120rpx" height="120rpx" />
 		</view>
@@ -9,6 +9,43 @@
 		</view>
 		<view class="iconfont icon-shezhi" />
 	</view>
+
+	<up-popup :show="popupShow" mode="right" :customStyle="{
+		width: '80vw',
+		padding: '0 20rpx',
+		background: '#F7F7FF'
+	}" zIndex="99" @close="close" @open="open">
+		<view class="change-user">
+			<view class="title">
+				账号信息
+			</view>
+			<view class="row" v-show="headportraitLoading">
+				<view class="label">
+					点击更换头像
+				</view>
+				<view class="profilePhoto">
+					<up-image :show-loading="true" :src="user.profilePhoto" width="80rpx" height="80rpx" />
+					<view class="loading">
+						<up-loading-icon mode="semicircle" />
+					</view>
+				</view>
+			</view>
+			<view v-show="!headportraitLoading" hover-class="navigator-hover">
+				<My_upload ref="upload" custom maxCount="1" @uploadCallback="uploadCallback"
+					@startUploading="startUploading">
+					<view class="row" style="width: calc(80vw);">
+						<view class="label">
+							点击更换头像
+						</view>
+						<view class="profilePhoto">
+							<up-image :show-loading="true" :src="user.profilePhoto" width="80rpx" height="80rpx" />
+						</view>
+					</view>
+				</My_upload>
+			</view>
+
+		</view>
+	</up-popup>
 </template>
 
 <script setup>
@@ -20,18 +57,64 @@ let user = reactive({
 	name: '',
 	phonenumber: '',
 	profilePhoto: "",
+	attinfos: []
 });
 
 onLoad(() => {
 	getProperty()
 	getUserMsg()
 	const userInfo = uni.getStorageSync('userMsg')
-	user.name = userInfo.name
-	user.phonenumber = userInfo.phonenumber
-	user.profilePhoto = userInfo.profilePhoto || '/static/image/user.png'
+	user.name = userInfo.name;
+	user.phonenumber = userInfo.phonenumber;
+	user.attinfos = userInfo.attinfos;
+	user.profilePhoto = userInfo.profilePhoto || '/static/image/user.png';
 });
 
-//headportrait
+let popupShow = ref(true),
+	headportraitLoading = ref(false);
+function close() {
+	popupShow.value = false
+}
+
+// 更换头像
+let upload = ref(null);
+
+function startUploading(e) {
+	headportraitLoading.value = true;
+}
+
+function uploadCallback({ attachmentids, fileList }) {
+	if (fileList.pop().usetype == 'headportrait') return;
+	$Http.basic({
+		"classname": "system.attachment.Attachment",
+		"method": "createFileLink",
+		content: {
+			ownertable: "sys_users",
+			ownerid: uni.getStorageSync('userMsg').userid,
+			usetype: 'headportrait',
+			attachmentids,
+			siteid: uni.getStorageSync("userMsg").siteid
+		}
+	}).then(res => {
+		console.log('跟进记录绑定附件', res)
+		if (res.code != '1') return uni.showToast({
+			title: res.msg,
+			icon: "none"
+		})
+		upload.value.deleteFile(user.attinfos.filter(v => v.usetype == 'headportrait')).then(res1 => {
+			if (res1) {
+				getUserMsg();
+				setTimeout(() => {
+					uni.showToast({
+						title: '头像更换成功',
+						icon: 'none'
+					});
+				}, 100);
+			}
+		})
+
+	})
+}
 
 function getUserMsg() {
 	$Http.basic({
@@ -41,16 +124,14 @@ function getUserMsg() {
 	}).then(res => {
 		console.log("res", res);
 		if (res.code == 1) {
-			user.name = res.data.name
-			user.phonenumber = res.data.phonenumber
-			user.profilePhoto = user.profilePhoto
-
-			let userMsg = uni.getStorageSync('userMsg')
-			userMsg.name = res.data.name
-			userMsg.phonenumber = res.data.phonenumber
-			userMsg.profilePhoto = res.data.profilePhoto || '/static/image/user.png'
-			uni.setStorageSync('userMsg', userMsg)
-
+			user.name = res.data.name;
+			user.phonenumber = res.data.phonenumber;
+			user.attinfos = res.data.attinfos;
+			headportraitLoading.value = false;
+			const headportrait = res.data.attinfos.find(v => v.usetype == 'headportrait');
+			user.profilePhoto = headportrait ? $Http.getSpecifiedImage(headportrait) : user.profilePhoto;
+			const userMsg = uni.getStorageSync('userMsg')
+			uni.setStorageSync('userMsg', Object.assign(userMsg, user))
 		}
 	})
 }
@@ -72,7 +153,6 @@ function getProperty() {
 	display: flex;
 	align-items: center;
 	width: 100%;
-	height: 100%;
 	background-color: #fff;
 	box-sizing: border-box;
 	padding: 40rpx;
@@ -106,4 +186,54 @@ function getProperty() {
 
 	}
 }
+
+.change-user {
+	padding-top: 55px;
+	box-sizing: border-box;
+
+	.title {
+		font-size: 28rpx;
+		color: #333;
+		margin-bottom: 30rpx;
+		padding-left: 20rpx;
+	}
+
+	.row {
+		width: 100%;
+		display: flex;
+		align-items: center;
+		justify-content: space-between;
+		background: #fff;
+		padding: 20rpx 30rpx;
+		border-radius: 16rpx;
+		box-sizing: border-box;
+
+		.label {
+			font-size: 28rpx;
+			color: #666;
+		}
+
+		.profilePhoto {
+			position: relative;
+			width: 80rpx;
+			height: 80rpx;
+			border-radius: 50%;
+			overflow: hidden;
+
+			.loading {
+				position: absolute;
+				top: 0;
+				left: 0;
+				width: 100%;
+				height: 100%;
+				display: flex;
+				align-items: center;
+				justify-content: center;
+				background: rgba(0, 0, 0, 0.09);
+				z-index: 1;
+			}
+		}
+
+	}
+}
 </style>

+ 12 - 19
utils/Http.js

@@ -10,6 +10,18 @@ class HTTP {
       withCredentials: true
     });
 
+    this.updateList = function (content, getList) {
+      content.copyContent = JSON.parse(JSON.stringify(content));
+      content.pageSize = (content.pageNumber - 1) * (content.pageSize || 20);
+      content.pageNumber = 1;
+      getList();
+    }
+    this.getSpecifiedImage = function (obj, getType = false) {
+      let type = getType ? "compressed" : "thumbnail";
+      let imgObj = obj.subfiles.find((v) => v.type == type);
+      return imgObj?.url;
+    }
+
     // 请求拦截器
     this.instance.interceptors.request.use((config) => {
       config.headers = config.headers || {};
@@ -75,25 +87,6 @@ class HTTP {
       });
   }
 
-  /**
-   * 静态方法 - 更新分页列表
-   */
-  static updateList(content, getList) {
-    content.copyContent = JSON.parse(JSON.stringify(content));
-    content.pageSize = (content.pageNumber - 1) * (content.pageSize || 20);
-    content.pageNumber = 1;
-    getList();
-  }
-
-  /**
-   * 静态方法 - 获取缩略图 / 压缩图
-   */
-  static getSpecifiedImage(obj, getType = false) {
-    let type = getType ? "compressed" : "thumbnail";
-    let imgObj = obj.subfiles.find((v) => v.type == type);
-    return imgObj?.url;
-  }
-
   /**
    * 处理 JSESSIONID
    */