zs 1 год назад
Родитель
Сommit
03acc3c99f

+ 7 - 5
pages/my/index.vue

@@ -3,7 +3,7 @@
 		<view class="one">
 			<view class="one_1" v-if="user&&user._id">
 				<view class="left">
-					<image v-if="user.icon&&user.icon.length>0" class="logo" :src="user.icon[0].url"></image>
+					<image v-if="user.icon&&user.icon.length>0&&user.icon" class="logo" :src="user.icon[0].url"></image>
 					<image v-else class="logo" :src="config.icon[0].url"></image>
 				</view>
 				<view class="right">
@@ -70,18 +70,20 @@
 	const config = ref({ logo: [], icon: [], file: [] });
 	// 遮罩层
 	const show = ref(false);
-	// user
-	const user = computed(() => {
-		return uni.getStorageSync('user');
-	})
+	const user = ref({ icon: [] });
 	// 字典表
 	const genderList = ref([]);
 	onShow(async () => {
 		await searchConfig();
+		await searchUser();
 		await searchOther();
 		await search();
 		if (!user.value) show.value = true
 	})
+	// user信息
+	const searchUser = async () => {
+		user.value = uni.getStorageSync('user');
+	};
 	// config信息
 	const searchConfig = async () => {
 		config.value = uni.getStorageSync('config');

+ 55 - 5
pagesMy/account/index.vue

@@ -75,7 +75,30 @@
 			let res;
 			if (user.value.role_type == 'Teacher') res = await $api(`teacher/${user.value._id}`, 'GET', {});
 			else res = await $api(`student/${user.value._id}`, 'GET', {});
-			if (res.errcode == '0') form.value = res.data
+			if (res.errcode == '0') {
+				if (res.data.cardType) {
+					const data = cardTypeList.value.find(i => i.value === res.data.cardType)
+					if (data) res.data.cardType_name = data.label
+				}
+				if (res.data.education) {
+					const data = educationList.value.find(i => i.value === res.data.education)
+					if (data) res.data.education_name = data.label
+				}
+				if (res.data.learnStatus) {
+					const data = learnStatusList.value.find(i => i.value === res.data.learnStatus)
+					if (data) res.data.learnStatus_name = data.label
+				}
+				if (res.data.grade) {
+					const data = gradeList.value.find(i => i.value === res.data.grade)
+					if (data) res.data.grade_name = data.label
+				}
+				if (res.data.subject) {
+					const data = subjectList.value.find(i => i.value === res.data.subject)
+					if (data) res.data.subject_name = data.label
+				}
+				form.value = res.data
+				uni.setStorageSync('user', { ...res.data, role_type: user.value.role_type });
+			}
 		}
 	};
 	// 删除图片
@@ -151,6 +174,10 @@
 		if (!obj.phone || obj.phone.trim() === '') {
 			errors.phone = '请填写手机号!';
 		}
+		// 检查email属性是否填写
+		if (!obj.is_show || obj.is_show.trim() === '') {
+			errors.is_show = '请选择是否公开!';
+		}
 		// 如果有错误,返回错误对象
 		if (Object.keys(errors).length > 0) {
 			return errors;
@@ -158,11 +185,25 @@
 		// 如果没有错误,返回null或undefined
 		return null;
 	}
-
+	// 处理两个对象合并
+	const mergeObjectsWithoutDuplicates = async (obj1, obj2) => {
+		return Object.keys({ ...obj1, ...obj2 }).reduce((acc, key) => {
+			if (!acc.hasOwnProperty(key)) {
+				if (key == 'cardType_name' || key == 'education_name' || key == 'learnStatus_name' || key == 'grade_name' || key == 'subject_name') {
+					delete acc[key]
+				} else {
+					// 如果累加器对象(acc)中不存在该键,则添加它
+					acc[key] = obj1.hasOwnProperty(key) ? obj1[key] : obj2[key];
+				}
+			}
+			return acc;
+		}, {});
+	}
 	// 保存
 	const formSubmit = async (e) => {
 		// 调用验证函数
-		const errorsInfo = await validateObject(form.value);
+		const data = await mergeObjectsWithoutDuplicates(e.detail.value, form.value);
+		const errorsInfo = await validateObject(data);
 		// 检查是否有错误
 		if (errorsInfo) {
 			errors.value = errorsInfo
@@ -173,8 +214,17 @@
 				}
 			}
 		} else {
-			console.log('所有字段都已填写');
-			console.log(form.value);
+			errors.value = {}
+			let res;
+			if (user.value.role_type == 'Teacher') res = await $api(`teacher/${form.value._id}`, 'POST', data);
+			else res = await $api(`student/${form.value._id}`, 'POST', data);
+			if (res.errcode == '0') {
+				await search();
+				uni.showToast({
+					title: '保存成功',
+					icon: 'success'
+				});
+			}
 		}
 	};
 	// provide

+ 3 - 2
pagesMy/account/path/teacher.vue

@@ -5,7 +5,7 @@
 				<view class="value other" style="display: none;">
 					<view class="title">id</view>
 					<view class="label">
-						<input name="id" class="input" :value="form._id" placeholder="请输入id" />
+						<input name="_id" class="input" :value="form._id" placeholder="请输入id" />
 					</view>
 				</view>
 				<view class="value icon">
@@ -108,12 +108,13 @@
 								:key="index" :label="item.label" :name="item.value">
 							</up-radio>
 						</up-radio-group>
+						<span v-if="errors.is_show" class="error-message">{{ errors.is_show }}</span>
 					</view>
 				</view>
 				<view class="brief other margin">
 					<view class="title">简介</view>
 					<view class="label">
-						<textarea :value="form.brief" placeholder="请输入简介" auto-height />
+						<textarea name='brief' :value="form.brief" placeholder="请输入简介" auto-height />
 					</view>
 				</view>
 				<view class="button">

+ 12 - 10
unpackage/dist/dev/mp-weixin/pages/my/index.js

@@ -21,17 +21,19 @@ const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
     common_vendor.inject("$config");
     const config$1 = common_vendor.ref({ logo: [], icon: [], file: [] });
     const show = common_vendor.ref(false);
-    const user = common_vendor.computed(() => {
-      return common_vendor.index.getStorageSync("user");
-    });
+    const user = common_vendor.ref({ icon: [] });
     const genderList = common_vendor.ref([]);
     common_vendor.onShow(async () => {
       await searchConfig();
+      await searchUser();
       await searchOther();
       await search();
       if (!user.value)
         show.value = true;
     });
+    const searchUser = async () => {
+      user.value = common_vendor.index.getStorageSync("user");
+    };
     const searchConfig = async () => {
       config$1.value = common_vendor.index.getStorageSync("config");
     };
@@ -74,16 +76,16 @@ const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
     };
     return (_ctx, _cache) => {
       return common_vendor.e({
-        a: common_vendor.unref(user) && common_vendor.unref(user)._id
-      }, common_vendor.unref(user) && common_vendor.unref(user)._id ? common_vendor.e({
-        b: common_vendor.unref(user).icon && common_vendor.unref(user).icon.length > 0
-      }, common_vendor.unref(user).icon && common_vendor.unref(user).icon.length > 0 ? {
-        c: common_vendor.unref(user).icon[0].url
+        a: user.value && user.value._id
+      }, user.value && user.value._id ? common_vendor.e({
+        b: user.value.icon && user.value.icon.length > 0 && user.value.icon
+      }, user.value.icon && user.value.icon.length > 0 && user.value.icon ? {
+        c: user.value.icon[0].url
       } : {
         d: config$1.value.icon[0].url
       }, {
-        e: common_vendor.t(common_vendor.unref(user).nick_name || "暂无昵称"),
-        f: common_vendor.t(getGender(common_vendor.unref(user).gender))
+        e: common_vendor.t(user.value.nick_name || "暂无昵称"),
+        f: common_vendor.t(getGender(user.value.gender))
       }) : {
         g: config$1.value.icon[0].url,
         h: common_vendor.o(($event) => show.value = true)

+ 58 - 4
unpackage/dist/dev/mp-weixin/pagesMy/account/index.js

@@ -63,8 +63,35 @@ const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
           res = await $api(`teacher/${user.value._id}`, "GET", {});
         else
           res = await $api(`student/${user.value._id}`, "GET", {});
-        if (res.errcode == "0")
+        if (res.errcode == "0") {
+          if (res.data.cardType) {
+            const data = cardTypeList.value.find((i) => i.value === res.data.cardType);
+            if (data)
+              res.data.cardType_name = data.label;
+          }
+          if (res.data.education) {
+            const data = educationList.value.find((i) => i.value === res.data.education);
+            if (data)
+              res.data.education_name = data.label;
+          }
+          if (res.data.learnStatus) {
+            const data = learnStatusList.value.find((i) => i.value === res.data.learnStatus);
+            if (data)
+              res.data.learnStatus_name = data.label;
+          }
+          if (res.data.grade) {
+            const data = gradeList.value.find((i) => i.value === res.data.grade);
+            if (data)
+              res.data.grade_name = data.label;
+          }
+          if (res.data.subject) {
+            const data = subjectList.value.find((i) => i.value === res.data.subject);
+            if (data)
+              res.data.subject_name = data.label;
+          }
           form.value = res.data;
+          common_vendor.index.setStorageSync("user", { ...res.data, role_type: user.value.role_type });
+        }
       }
     };
     const deletePic = (event) => {
@@ -128,13 +155,29 @@ const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
       if (!obj.phone || obj.phone.trim() === "") {
         errors2.phone = "请填写手机号!";
       }
+      if (!obj.is_show || obj.is_show.trim() === "") {
+        errors2.is_show = "请选择是否公开!";
+      }
       if (Object.keys(errors2).length > 0) {
         return errors2;
       }
       return null;
     };
+    const mergeObjectsWithoutDuplicates = async (obj1, obj2) => {
+      return Object.keys({ ...obj1, ...obj2 }).reduce((acc, key) => {
+        if (!acc.hasOwnProperty(key)) {
+          if (key == "cardType_name" || key == "education_name" || key == "learnStatus_name" || key == "grade_name" || key == "subject_name") {
+            delete acc[key];
+          } else {
+            acc[key] = obj1.hasOwnProperty(key) ? obj1[key] : obj2[key];
+          }
+        }
+        return acc;
+      }, {});
+    };
     const formSubmit = async (e) => {
-      const errorsInfo = await validateObject(form.value);
+      const data = await mergeObjectsWithoutDuplicates(e.detail.value, form.value);
+      const errorsInfo = await validateObject(data);
       if (errorsInfo) {
         errors.value = errorsInfo;
         for (const key in errorsInfo) {
@@ -143,8 +186,19 @@ const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
           }
         }
       } else {
-        console.log("所有字段都已填写");
-        console.log(form.value);
+        errors.value = {};
+        let res;
+        if (user.value.role_type == "Teacher")
+          res = await $api(`teacher/${form.value._id}`, "POST", data);
+        else
+          res = await $api(`student/${form.value._id}`, "POST", data);
+        if (res.errcode == "0") {
+          await search();
+          common_vendor.index.showToast({
+            title: "保存成功",
+            icon: "success"
+          });
+        }
       }
     };
     common_vendor.provide("form", form);

+ 6 - 2
unpackage/dist/dev/mp-weixin/pagesMy/account/path/teacher.js

@@ -134,8 +134,12 @@ const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
           placement: "row",
           modelValue: common_vendor.unref(form).is_show
         }),
-        P: common_vendor.unref(form).brief,
-        Q: common_vendor.o(
+        P: common_vendor.unref(errors).is_show
+      }, common_vendor.unref(errors).is_show ? {
+        Q: common_vendor.t(common_vendor.unref(errors).is_show)
+      } : {}, {
+        R: common_vendor.unref(form).brief,
+        S: common_vendor.o(
           //@ts-ignore
           (...args) => common_vendor.unref(formSubmit) && common_vendor.unref(formSubmit)(...args)
         )

Разница между файлами не показана из-за своего большого размера
+ 1 - 1
unpackage/dist/dev/mp-weixin/pagesMy/account/path/teacher.wxml