"use strict";
|
const common_vendor = require("../../common/vendor.js");
|
const stores_user = require("../../stores/user.js");
|
const apiservice_apiService = require("../../apiservice/apiService.js");
|
const _sfc_main = {
|
__name: "settings",
|
setup(__props) {
|
const userStore = stores_user.useUserStore();
|
const selectedavatarUrl = common_vendor.ref(0);
|
const sex = common_vendor.ref("male");
|
const username = common_vendor.ref("");
|
const phone = common_vendor.ref("");
|
function userNameInput(e) {
|
common_vendor.index.__f__("log", "at pages/ucenter/settings.vue:74", e.detail);
|
username.value = e.detail.value;
|
}
|
function onChooseAvatar(e) {
|
common_vendor.index.__f__("log", "at pages/ucenter/settings.vue:79", e.detail);
|
selectedavatarUrl.value = e.detail.avatarUrl;
|
}
|
function onSexChange(e) {
|
sex.value = e.detail.value;
|
}
|
function validateForm() {
|
if (!username.value.trim()) {
|
common_vendor.index.showToast({
|
title: "姓名不能为空",
|
icon: "none"
|
});
|
return false;
|
}
|
if (username.value.length > 10) {
|
common_vendor.index.showToast({
|
title: "姓名不能超过10个字",
|
icon: "none"
|
});
|
return false;
|
}
|
if (phone.value) {
|
const phoneReg = /^1\d{10}$/;
|
if (!phoneReg.test(phone.value)) {
|
common_vendor.index.showToast({
|
title: "手机号格式不正确",
|
icon: "none"
|
});
|
return false;
|
}
|
}
|
return true;
|
}
|
async function saveUser() {
|
if (!validateForm())
|
return;
|
try {
|
userStore.saveUserInfo({
|
username: username.value,
|
avatarUrl: selectedavatarUrl.value,
|
sex: sex.value,
|
phone: phone.value
|
});
|
if (userStore.id) {
|
apiservice_apiService.apiService.touristUpdate({
|
id: userStore.id,
|
username: userStore.username,
|
avatarurl: userStore.avatarUrl,
|
sex: userStore.sex,
|
phone: userStore.phone
|
}).then((res) => {
|
if (res.code === 1e3) {
|
common_vendor.index.__f__("log", "at pages/ucenter/settings.vue:141", "游客更新成功:");
|
common_vendor.index.showToast({
|
title: "保存成功",
|
icon: "success",
|
duration: 1500,
|
success: () => {
|
setTimeout(() => {
|
common_vendor.index.switchTab({
|
url: "/pages/index/index"
|
});
|
}, 1500);
|
}
|
});
|
} else {
|
common_vendor.index.__f__("warn", "at pages/ucenter/settings.vue:156", "游客更新失败:", res.message);
|
common_vendor.index.showToast({
|
title: "保存失败",
|
icon: "none",
|
duration: 1500
|
});
|
}
|
}).catch((err) => {
|
common_vendor.index.__f__("error", "at pages/ucenter/settings.vue:165", "游客更新错误:", err);
|
common_vendor.index.showToast({
|
title: "网络错误",
|
icon: "none",
|
duration: 1500
|
});
|
});
|
} else {
|
common_vendor.index.showToast({
|
title: "网络错误",
|
icon: "none",
|
duration: 1500
|
});
|
}
|
} catch (err) {
|
common_vendor.index.__f__("error", "at pages/ucenter/settings.vue:181", err);
|
common_vendor.index.showToast({
|
title: "保存失败",
|
icon: "none"
|
});
|
}
|
}
|
common_vendor.onMounted(() => {
|
if (userStore.username) {
|
username.value = userStore.username;
|
}
|
if (userStore.phone) {
|
phone.value = userStore.phone;
|
}
|
if (userStore.sex) {
|
sex.value = userStore.sex;
|
}
|
if (userStore.avatarUrl) {
|
selectedavatarUrl.value = userStore.avatarUrl;
|
}
|
});
|
return (_ctx, _cache) => {
|
return {
|
a: selectedavatarUrl.value,
|
b: common_vendor.o(onChooseAvatar),
|
c: sex.value === "male",
|
d: sex.value === "female",
|
e: common_vendor.o(onSexChange),
|
f: sex.value,
|
g: username.value,
|
h: common_vendor.o(userNameInput),
|
i: common_vendor.o(userNameInput),
|
j: phone.value,
|
k: common_vendor.o(($event) => phone.value = $event.detail.value),
|
l: common_vendor.o(saveUser)
|
};
|
};
|
}
|
};
|
wx.createPage(_sfc_main);
|
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/ucenter/settings.js.map
|