yyb
8 小时以前 b041fdf28a8935137c2efa7024cf3451d4375351
pages/sys/user/index.vue
@@ -1,25 +1,57 @@
<template>
  <view class="my">
    <view class="my-head">
      <u-navbar title="我的" :border-bottom="false" :background="background" :title-bold="true" title-color="#fff"
        :is-back="false" />
      <u-navbar
        title="我的"
        :border-bottom="false"
        :background="background"
        :title-bold="true"
        title-color="#fff"
        :is-back="false"
      />
      <view class="my-head-content" @click="navTo('info')">
        <u-avatar :src="image" size="240"></u-avatar>
        <p style="font-weight: bold;
font-size: 34rpx;
color: #333333;margin-bottom: 12rpx;">{{
  vuex_username || $t("login.noLogin")
          }}</p>
        <p
          style="
            font-weight: bold;
            font-size: 34rpx;
            color: #333333;
            margin-bottom: 12rpx;
          "
        >
          {{ vuex_username || $t("login.noLogin") }}
        </p>
        <!-- TODO 对接部门 -->
        <p style="font-weight: 500;
font-size: 28rpx;
color: #666666;">生产部门一</p>
        <p style="font-weight: 500; font-size: 28rpx; color: #666666">
          生产部门一
        </p>
      </view>
    </view>
    <u-button type="primary" style="margin: 30rpx;" :loading="loading" @click="logout" :custom-style="{
      backgroundColor: '#214DED',
      height: '80rpx'
    }" class="btn">{{ $t("login.logoutButton") }}</u-button>
    <u-button
      type="primary"
      style="margin: 30rpx"
      :loading="loading"
      @click="logout"
      :custom-style="{
        backgroundColor: '#214DED',
        height: '80rpx',
      }"
      class="btn"
      >{{ $t("login.logoutButton") }}</u-button
    >
    <u-button
      type="primary"
      style="margin: 30rpx"
      :loading="refreshLoading"
      @click="refresh"
      :custom-style="{
        backgroundColor: '#214DED',
        height: '80rpx',
      }"
      class="btn1"
      >检查更新</u-button
    >
      <view  class="currentVersion">版本号:{{ currentVersion }}</view>
  </view>
</template>
@@ -29,58 +61,144 @@
  data() {
    return {
      background: {
        background: 'transparent'
        background: "transparent",
      },
      loading: false,
      refreshLoading: false,
      image: undefined,
    }
      currentVersion: "1.0.0",
    };
  },
  onLoad() {
    this.image = config.baseUrl + this.vuex_user.avatar;
  },
  methods: {
    logout() {
      this.$u.api.logout().then((res) => {
        this.$u.toast(res.message);
    refresh() {
      this.refreshLoading = true;
      uni.showToast({
        title: "检查更新中...",
        icon: "loading",
      });
      this.$u.api
        .checkUpdate({
          currentVersion: this.currentVersion,
        })
        .then((res) => {
          console.log("checkUpdate", res);
          if (!res.hasUpdate) {
            uni.showToast({
              title: "当前版本为最新版本",
              icon: "success",
            });
          } else {
            let that = this;
            uni.showModal({
              title: "提示",
              content: "发现新版本,是否下载?",
              success: function (t) {
                if (t.confirm) {
                  that.downloadApk(res.downloadUrl);
                } else if (t.cancel) {
                  return;
                }
              },
            });
          }
          this.refreshLoading = false;
        });
    },
    // downloadPda() {
    //   this.$u.api
    //     .downloadPda({
    //       // currentVersion: this.currentVersion,
    //     })
    //     .then((res) => {
    //       this.downloadApk(res.url, res.fileSize);
    //     });
    // },
    downloadApk(url) {
      uni.showLoading({ title: "下载中,请勿操作" });
      console.log("downloadApk", url);
      uni.downloadFile({
        url: url,
        success: (res) => {
          // if (res.statusCode === 200) {
          const tempPath = res.tempFilePath;
        //清空存储信息
        this.$u.vuex("vuex_token", "");
        this.$u.vuex("vuex_refresh_token", "");
        this.$u.vuex("vuex_username", "");
        this.$u.vuex("vuex_userId", "");
        this.$u.vuex("vuex_client_id", "");
        this.$u.vuex("vuex_user", {});
        setTimeout(() => {
          uni.reLaunch({
            url: "/pages/sys/login/index",
          // 调用设备 API 进行本地安装
          plus.runtime.install(
            tempPath,
            {},
            () => {
              // uni.hideLoading();
              uni.showToast({
                title: "安装成功",
              });
            },
            (err) => {
              // uni.hideLoading();
              uni.showToast({
                title: "安装失败:" + err.message,
              });
            }
          );
          // } else {
          //   uni.hideLoading();
          //   uni.showToast({
          //     title: '下载失败'
          //   });
          // }
        },
        fail: (err) => {
          console.error(err);
          uni.hideLoading();
          uni.showToast({
            title: "下载出错",
          });
        }, 500);
      })
      .catch((err) => {
        this.$u.api.workReporting
               .getWorkshopOrder({})
               .then((res) => {
               });
      })
        },
      });
    },
    logout() {
      this.$u.api
        .logout()
        .then((res) => {
          this.$u.toast(res.message);
          //清空存储信息
          this.$u.vuex("vuex_token", "");
          this.$u.vuex("vuex_refresh_token", "");
          this.$u.vuex("vuex_username", "");
          this.$u.vuex("vuex_userId", "");
          this.$u.vuex("vuex_client_id", "");
          this.$u.vuex("vuex_user", {});
          setTimeout(() => {
            uni.reLaunch({
              url: "/pages/sys/login/index",
            });
          }, 500);
        })
        .catch((err) => {
          this.$u.api.workReporting.getWorkshopOrder({}).then((res) => {});
        });
    },
    navTo(url) {
      // uni.navigateTo({
      //   url: url,
      // });
    },
  }
}
  },
};
</script>
<style lang="scss" scoped>
.my {
  height: 100%;
  background: linear-gradient(to bottom, #E5F0FF, #F6F9FF);
  background: linear-gradient(to bottom, #e5f0ff, #f6f9ff);
  .my-head {
    height: 320rpx;
    background-image: url('~@/static/custom/user/bg2.png');
    background-image: url("~@/static/custom/user/bg2.png");
    background-size: 100% auto;
    background-repeat: no-repeat;
    position: relative;
@@ -99,7 +217,20 @@
  .btn {
    position: fixed;
    bottom: 160rpx;
    bottom: 320rpx;
    width: calc(100% - 60rpx);
  }
  .btn1 {
    position: fixed;
    bottom: 200rpx;
    width: calc(100% - 60rpx);
  }
  .currentVersion {
    position: fixed;
    color: #010101;
    font-size: 32rpx;
    text-align: center;
    bottom: 150rpx;
    width: calc(100% - 60rpx);
  }
}