wangzhibo
2025-10-23 cad64c1de2c45856b0774933c5801b05b64984e8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
"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