acdr-ui/dist/dev/mp-weixin/pages/settings/index.js

200 lines
7.6 KiB
JavaScript

"use strict";
var __async = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};
const common_vendor = require("../../common/vendor.js");
const store_config = require("../../store/config.js");
require("../../store/index.js");
const utils_http = require("../../utils/http.js");
const utils_commUtils = require("../../utils/commUtils.js");
const service_fileservice = require("../../service/fileservice.js");
const service_userService = require("../../service/userService.js");
const store_user = require("../../store/user.js");
if (!Array) {
const _easycom_wd_img2 = common_vendor.resolveComponent("wd-img");
const _easycom_wd_picker2 = common_vendor.resolveComponent("wd-picker");
const _easycom_wd_icon2 = common_vendor.resolveComponent("wd-icon");
const _easycom_wd_popup2 = common_vendor.resolveComponent("wd-popup");
const _component_layout_default_uni = common_vendor.resolveComponent("layout-default-uni");
(_easycom_wd_img2 + _easycom_wd_picker2 + _easycom_wd_icon2 + _easycom_wd_popup2 + _component_layout_default_uni)();
}
const _easycom_wd_img = () => "../../node-modules/wot-design-uni/components/wd-img/wd-img.js";
const _easycom_wd_picker = () => "../../node-modules/wot-design-uni/components/wd-picker/wd-picker.js";
const _easycom_wd_icon = () => "../../node-modules/wot-design-uni/components/wd-icon/wd-icon.js";
const _easycom_wd_popup = () => "../../node-modules/wot-design-uni/components/wd-popup/wd-popup.js";
if (!Math) {
(_easycom_wd_img + _easycom_wd_picker + _easycom_wd_icon + _easycom_wd_popup + LoadingAnimation)();
}
const LoadingAnimation = () => "../../components/LoadingAnimation.js";
const _sfc_main = {
__name: "index",
setup(__props) {
const configStore = store_config.useConfigStore();
const userStore = store_user.useUserStore();
const languages = configStore.languages;
const selectedLanguage = common_vendor.ref(languages["zh-Hans"]);
const sinfo = common_vendor.ref({});
const showUserNamePopup = common_vendor.ref(false);
const newUserName = common_vendor.ref("");
const loading = common_vendor.ref(false);
const languageOptions = common_vendor.computed(
() => Object.entries(languages).map(([key, value]) => ({
value: key,
label: value
}))
);
const handleLanguageChange = ({ value }) => {
configStore.changeLanguage(selectedLanguage.value);
};
const goToRealNameAuth = () => {
common_vendor.index.navigateTo({
url: "/pages/permission/real-name-auth"
});
};
const goToBindPhone = () => {
common_vendor.index.navigateTo({
url: "/pages/permission/bind-phone"
});
};
const getSettingInfo = () => __async(this, null, function* () {
const settingInfo = yield utils_http.httpGet("/setting/info");
try {
if (settingInfo.code === 200) {
sinfo.value = settingInfo.data;
} else {
utils_commUtils.toast(settingInfo.message);
}
} catch (e) {
console.log(e);
}
});
const updateUserName = () => __async(this, null, function* () {
if (!newUserName.value) {
utils_commUtils.toast("用户名不能为空");
return;
}
const response = yield utils_http.httpPost("/setting/updateUserName", {}, { userName: newUserName.value });
if (response.code === 200) {
sinfo.value.userName = newUserName.value;
utils_commUtils.toast("用户名修改成功");
showUserNamePopup.value = false;
yield getSettingInfo();
yield service_userService.getUserInfo();
} else {
utils_commUtils.toast(response.message);
}
});
const updateAvatar = () => __async(this, null, function* () {
try {
const path = yield service_fileservice.chooseImage();
if (!path || path == "") {
utils_commUtils.toast("图片上传失败,请检查你的网络情况!");
return;
}
const res = yield utils_http.httpPost("/setting/updateUserAvatar", {}, { userAvatar: path });
if (res.code == 200 && res.data) {
utils_commUtils.toast("头像更新成功");
yield getSettingInfo();
yield service_userService.getUserInfo();
}
} catch (e) {
console.log(e);
utils_commUtils.toast("头像更新失败");
}
});
const logout = () => __async(this, null, function* () {
const logRes = yield utils_http.httpGet("/user/logout");
if (logRes.code == 200) {
common_vendor.index.showToast({ title: "退出成功", icon: "none" });
} else {
common_vendor.index.showToast({ title: logRes.msg, icon: "none" });
}
userStore.clearUserInfo();
common_vendor.index.reLaunch({
url: "/pages/login/index"
});
});
common_vendor.onLoad(() => __async(this, null, function* () {
loading.value = true;
yield getSettingInfo();
loading.value = false;
}));
return (_ctx, _cache) => {
return common_vendor.e({
a: sinfo.value.userAvatar != void 0
}, sinfo.value.userAvatar != void 0 ? {
b: common_vendor.p({
width: 100,
height: 100,
round: true,
mode: "aspectFill",
src: sinfo.value.userAvatar ? common_vendor.unref(utils_commUtils.imgUrl)(sinfo.value.userAvatar) : common_vendor.unref(utils_commUtils.imgUrl)("")
})
} : {}, {
c: common_vendor.o(updateAvatar),
d: common_vendor.o(handleLanguageChange),
e: common_vendor.o(($event) => selectedLanguage.value = $event),
f: common_vendor.p({
columns: languageOptions.value,
label: "选择语言",
modelValue: selectedLanguage.value
}),
g: common_vendor.t(sinfo.value.userName),
h: common_vendor.p({
name: "right",
size: "16"
}),
i: common_vendor.o(($event) => showUserNamePopup.value = true),
j: common_vendor.t(sinfo.value.phone),
k: common_vendor.p({
name: "right",
size: "16"
}),
l: common_vendor.o(goToBindPhone),
m: sinfo.value.isAuth
}, sinfo.value.isAuth ? {} : {}, {
n: common_vendor.p({
name: "right",
size: "16"
}),
o: common_vendor.o(($event) => !sinfo.value.isAuth ? goToRealNameAuth() : common_vendor.unref(utils_commUtils.toast)("你已经实名了")),
p: newUserName.value,
q: common_vendor.o(($event) => newUserName.value = $event.detail.value),
r: common_vendor.o(updateUserName),
s: common_vendor.o(($event) => showUserNamePopup.value = false),
t: common_vendor.o(($event) => showUserNamePopup.value = $event),
v: common_vendor.p({
position: "center",
["custom-style"]: "padding: 20px;",
modelValue: showUserNamePopup.value
}),
w: common_vendor.o(logout),
x: common_vendor.o(($event) => loading.value = $event),
y: common_vendor.p({
modelValue: loading.value
})
});
};
}
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-b4180827"]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=index.js.map