settings.vue 6.79 KB
Newer Older
1 2 3
<template>
  <div class="settings">
    <van-cell-group class="group-1">
leiqingsong's avatar
leiqingsong committed
4
      <van-cell title="用户名" :value="userName" />
leiqingsong's avatar
leiqingsong committed
5
      <!--is-link @click="onModefy" -->
leiqingsong's avatar
leiqingsong committed
6
      <van-cell center title="头像" is-link @click="onModefy">
leiqingsong's avatar
leiqingsong committed
7
        <img class="avatar-img" :src="imageBaseUrl + avatar" alt="头像" />
8
      </van-cell>
9
      <van-cell title="我的邀请码" :value="myInviteCode" />
10 11
    </van-cell-group>
    <van-cell-group>
12
      <van-cell
13
        class="van-less"
14
        is-link
leiqingsong's avatar
leiqingsong committed
15
        title="推荐人邀请码"
16 17 18
        :value="inviteeCode"
        @click="fillInviterCode"
      />
19 20 21 22 23 24
      <van-cell
        is-link
        title="软件更新"
        :value="version"
        @click="updateVersion"
      />
leiqingsong's avatar
leiqingsong committed
25
      <van-cell is-link title="用户协议" @click="jumpToInstructions" />
26
    </van-cell-group>
leiqingsong's avatar
leiqingsong committed
27

leiqingsong's avatar
leiqingsong committed
28
    <a href="redirect://xts.com/login_activity?hideBack=true">
leiqingsong's avatar
leiqingsong committed
29 30 31 32
      <van-button size="large" class="logout-btn" @click="logout"
        >退出登录</van-button
      >
    </a>
33 34 35 36 37 38

    <base-dialog
      base-dialog-title="推荐人邀请码"
      base-dialog-btn="提交"
      :base-dialog-show="inviteeCodeDialog"
      :base-dialog-show-close="true"
leiqingsong's avatar
leiqingsong committed
39
      @onClose="onCloseDialog"
40 41 42 43 44 45
      @onClick="onFillInviteeCode"
    >
      <div slot="content">
        <p class="content-tip">请输入您的推荐人邀请码</p>
        <van-field
          v-model="fillCode"
leiqingsong's avatar
leiqingsong committed
46
          maxlength="6"
47 48 49 50 51
          class="validCodeInput"
          placeholder="请输入"
        />
      </div>
    </base-dialog>
52 53 54 55 56 57 58 59 60 61 62

    <base-dialog
      base-dialog-title="版本更新"
      :base-dialog-show="versionShow"
      :base-dialog-btn="updateBtn"
      @onClick="onUpdateVersion"
    >
      <div slot="content" class="update-content">
        <span class="update-tip">{{ updateResult }}</span>
      </div>
    </base-dialog>
63 64 65 66
  </div>
</template>

<script>
67
import { versionUpdate } from "@/api/base";
leiqingsong's avatar
leiqingsong committed
68
import { getUserInfo2 } from "@/api/user";
leiqingsong's avatar
leiqingsong committed
69
import { logout } from "@/api/user";
leiqingsong's avatar
leiqingsong committed
70
import { fillInviteCode } from "@/api/user";
71
import BaseDialog from "../components/BaseDialog.vue";
72
export default {
73
  components: { BaseDialog },
74 75 76
  name: "Settings",
  data() {
    return {
77
      myInviteCode: "",
78 79 80 81 82 83
      downAppUrl: "",
      needUpdate: false,
      updateBtn: "关闭",
      updateResult: "",
      versionShow: false,
      version: "",
leiqingsong's avatar
leiqingsong committed
84
      userName: "",
leiqingsong's avatar
leiqingsong committed
85
      imageBaseUrl: "",
leiqingsong's avatar
leiqingsong committed
86
      headImage: "",
leiqingsong's avatar
leiqingsong committed
87
      avatar: "",
88 89
      fileList: [],
      fillCode: "",
leiqingsong's avatar
leiqingsong committed
90
      inviteeCode: "请填写推荐人邀请码",
91
      inviteeCodeDialog: false
92 93
    };
  },
leiqingsong's avatar
leiqingsong committed
94
  mounted() {
leiqingsong's avatar
leiqingsong committed
95
    this.imageBaseUrl = process.env.VUE_APP_BASE_URL;
96
    this.getAppVersion();
97 98 99
    setTimeout(() => {
      console.log("读取用户信息");
      this.getUser();
leiqingsong's avatar
leiqingsong committed
100
    }, 300);
leiqingsong's avatar
leiqingsong committed
101
  },
102
  methods: {
103 104 105 106 107 108 109 110
    onUpdateVersion() {
      if (this.needUpdate) {
        location.href = this.downAppUrl;
      } else {
        this.versionShow = false;
      }
    },
    updateVersion() {
leiqingsong's avatar
leiqingsong committed
111
      const params = {
112
        type: this.$bridgeToAppFun.userAgent === "ios" ? 1 : 2,
leiqingsong's avatar
leiqingsong committed
113
        version: this.version.substr(2)
114
      };
leiqingsong's avatar
leiqingsong committed
115
      versionUpdate(params).then(res => {
116
        this.versionShow = true;
leiqingsong's avatar
leiqingsong committed
117
        if (res.code == 1) {
leiqingsong's avatar
leiqingsong committed
118
          this.updateResult = res.message;
119
          this.needUpdate = false;
leiqingsong's avatar
leiqingsong committed
120
        } else if (res.code == 0) {
121 122 123 124 125 126 127
          this.downAppUrl = res.data;
          this.updateResult = "最新版App下载地址:" + res.data;
          this.updateBtn = "下载最新版App";
          this.needUpdate = true;
        }
      });
    },
leiqingsong's avatar
leiqingsong committed
128
    async getAppVersion() {
leiqingsong's avatar
leiqingsong committed
129
      console.log("设置里获取到的版本号", this.$bridgeToAppFun.getAppVersion());
leiqingsong's avatar
leiqingsong committed
130 131 132 133 134 135 136
      if (this.$bridgeToAppFun.userAgent === "ios") {
        this.$bridgeToAppFun.getAppVersion().then(res => {
          this.version = "版本" + res;
        });
      } else {
        this.version = "版本" + this.$bridgeToAppFun.getAppVersion();
      }
137
    },
leiqingsong's avatar
leiqingsong committed
138
    getUser() {
leiqingsong's avatar
leiqingsong committed
139
      const params = {
leiqingsong's avatar
leiqingsong committed
140
        userId: JSON.parse(localStorage.getItem("user")).userId
leiqingsong's avatar
leiqingsong committed
141
      };
leiqingsong's avatar
leiqingsong committed
142
      console.log("setting-userId", params);
leiqingsong's avatar
leiqingsong committed
143 144 145 146 147 148
      getUserInfo2(params)
        .then(res => {
          if (res.userId) {
            localStorage.setItem("user", JSON.stringify(res));
            this.$nextTick(() => {
              this.userName = res.userId;
149
              this.myInviteCode = res.inviteCode;
leiqingsong's avatar
leiqingsong committed
150 151 152 153 154 155 156 157 158 159 160 161 162 163
              this.inviteeCode =
                res.beInvitedCode == 1
                  ? "请填写推荐人邀请码"
                  : res.beInvitedCode;
              this.avatar = res.headImage;
              this.headImage = res.headImage;
            });
          }
        })
        .catch(err => {
          if (err.response.status === 502) {
            this.$toast("服务在升级,请稍后重试");
          }
        });
leiqingsong's avatar
leiqingsong committed
164
    },
leiqingsong's avatar
leiqingsong committed
165
    logout() {
166 167
      localStorage.clear();
      logout().then();
leiqingsong's avatar
leiqingsong committed
168
      this.$bridgeToAppFun.logoutToApp();
leiqingsong's avatar
leiqingsong committed
169
    },
leiqingsong's avatar
leiqingsong committed
170 171 172
    jumpToInstructions() {
      this.$router.push("/instructions");
    },
173
    onModefy() {
leiqingsong's avatar
leiqingsong committed
174 175 176
      this.$router.push({
        path: "/modefy-avatar",
        query: {
leiqingsong's avatar
leiqingsong committed
177
          headImage: this.headImage
leiqingsong's avatar
leiqingsong committed
178 179
        }
      });
180
    },
leiqingsong's avatar
leiqingsong committed
181 182 183
    onCloseDialog() {
      this.inviteeCodeDialog = false;
    },
184
    onFillInviteeCode() {
leiqingsong's avatar
leiqingsong committed
185
      if (!this.fillCode) {
leiqingsong's avatar
leiqingsong committed
186
        this.$toast.fail("请填写推荐人邀请码");
leiqingsong's avatar
leiqingsong committed
187 188 189
        return;
      }
      if (!/^[A-z|\d]{6}$/.test(this.fillCode)) {
leiqingsong's avatar
leiqingsong committed
190
        this.$toast.fail("邀请码只支持6位数字+字母的组合");
leiqingsong's avatar
leiqingsong committed
191 192
        return;
      }
193
      this.inviteeCodeDialog = false;
leiqingsong's avatar
leiqingsong committed
194 195
      const params = {
        inviteCode: this.fillCode,
leiqingsong's avatar
leiqingsong committed
196
        userId: JSON.parse(localStorage.getItem("user")).userId
leiqingsong's avatar
leiqingsong committed
197
      };
leiqingsong's avatar
leiqingsong committed
198 199 200 201 202 203 204 205 206 207 208 209 210
      fillInviteCode(params)
        .then(res => {
          if (res.code == 0) {
            // console.log('成功');
            this.inviteeCode = this.fillCode;
          } else {
            this.$toast.fail(res.message);
          }
        })
        .catch(err => {
          console.log(err);
          this.$toast.fail(err);
        });
211 212
    },
    fillInviterCode() {
leiqingsong's avatar
leiqingsong committed
213 214 215 216
      if (
        this.inviteeCode === "请填写推荐人邀请码" ||
        this.inviteeCode == "1"
      ) {
217 218 219
        this.inviteeCodeDialog = true;
        this.fillCode = "";
      }
220 221 222 223 224 225 226 227 228
    }
  }
};
</script>

<style lang="scss" scoped>
.settings {
  box-sizing: border-box;
  padding: 10px 16px;
leiqingsong's avatar
leiqingsong committed
229 230
  .van-less {
    .van-cell__right-icon {
231 232 233
      display: none;
    }
  }
234 235 236
}
.group-1 {
  margin-bottom: 10px;
237
  .avatar-img {
238 239 240 241 242 243 244 245
    width: 37px;
    height: 37px;
    border-radius: 50%;
  }
}
.logout-btn {
  margin: 10px 0;
}
246 247 248 249 250 251 252 253 254 255 256
.content-tip {
  text-align: center;
  font-size: 14px;
  color: #333333;
}
.validCodeInput {
  width: 245px;
  margin: 35px auto;
  background-color: #f9f9f9;
  border-radius: 20px;
}
257 258 259 260 261 262 263 264 265 266
.update-content {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
}
.update-tip {
  width: 90%;
  font-size: 18px;
  word-break: break-all;
leiqingsong's avatar
leiqingsong committed
267
  text-align: center;
268
}
269
</style>