info.vue 5.82 KB
<!--
 * @Date: 2024-10-18 18:00:47
 * @LastEditors: hookehuyr hookehuyr@gmail.com
 * @LastEditTime: 2024-12-11 17:36:43
 * @FilePath: /hager/src/views/user/info.vue
 * @Description: 文件描述
-->
<template>
  <div class="hager-info-page">
    <div class="input-title">我的信息</div>
    <div style="padding: 1rem 1.5rem 1rem 1rem;">
      <hagerInput type="email" :disable="status !== 'edit'" required v-model="email" placeholder="请输入注册邮箱地址" />
      <!-- <hagerInput type="pwd" :disable="status !== 'edit'" required v-model="pwd" placeholder="请输入登录密码" /> -->
      <hagerInput type="username" :disable="status !== 'edit'" v-model="username" placeholder="请输入姓名" />
      <hagerInput type="tel" :disable="status !== 'edit'" v-model="tel" placeholder="请输入联系电话" />
      <hagerInput type="corp" :disable="status !== 'edit'" v-model="corp" placeholder="请输入公司名称" />
      <hagerInput type="department" :disable="status !== 'edit'" v-model="department" placeholder="请输入所属部门和职位" />
    </div>
    <div class="info-footer">
      <div v-if="status !== 'edit'" class="submit-btn" @click="onHandle">修改信息</div>
      <div v-else class="edit-box">
        <div class="cancel btn" @click="onCancel">取消</div>
        <div class="confirm btn" @click="onSubmit">确定</div>
      </div>
      <div class="info-subsidiary">
        <div class="privacy" @click="openPrivacy"><span>隐私政策</span></div>
      </div>
    </div>
    <el-dialog :title="privacyInfo.post_title" :visible.sync="dialogVisible" top="10vh" width="60%">
      <privacy :content="privacyInfo.post_content" style="overflow-y: scroll; max-height: 70vh;"></privacy>
    </el-dialog>

    <el-drawer
      :title="privacyInfo.post_title"
      size="100%"
      :visible.sync="drawer"
      :direction="direction">
      <privacy :content="privacyInfo.post_content" style="padding: 1rem;"></privacy>
    </el-drawer>
  </div>
</template>

<script>
import mixin from 'common/mixin';
import hagerInput from '@/components/common/hagerInput.vue';
import $ from 'jquery';
import privacy from '@/components/privacy.vue';
import { getUserInfoAPI, editUserInfoAPI, getArticleAPI } from "@/api/hager.js";
import { MessageBox, Message } from 'element-ui';

export default {
  mixins: [mixin.init],
  data () {
    return {
      email: '',
      pwd: '',
      username: '',
      tel: '',
      corp: '',
      department: '',
      status: '',
      dialogVisible: false,
      drawer: false,
      direction: 'rtl',
      privacyInfo: {
        post_title: '',
        content: '',
      }
    }
  },
  async mounted () {
    if ($('#router-view').outerHeight() < $('.user-box').height()) {
      $('#router-view').height($('.user-box').outerHeight())
    }
    // 获取用户信息
    this.getUserInfo();
    // 获取隐私信息
    this.getPrivacyInfo();
  },
  methods: {
    async getPrivacyInfo () {
      const { code, data } = await getArticleAPI({ id: '84775' });
      if (code === 1) {
        this.privacyInfo = data;
      }
    },
    async getUserInfo () {
      const { code, data } = await getUserInfoAPI();
      if (code === 1) { // 已登录
        this.email = data.email;
        this.username = data.username;
        this.tel = data.mobile;
        this.corp = data.company;
        this.department = data.department;
      }
    },
    onHandle () {
      this.status = 'edit';
    },
    async onSubmit () {
      if (!this.email) {
        Message({
          type: 'error',
          message: '邮箱地址不能空'
        });
        return;
      }
      // 检验邮箱地址有效性
      if (!/^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(this.email)) {
        Message({
          type: 'error',
          message: '邮箱地址格式不正确'
        });
        return;
      }
      const { code, msg } = await editUserInfoAPI({
        email: this.email,
        username: this.username,
        mobile: this.tel,
        company: this.corp,
        department: this.department
      });
      if (code) {
        Message({
          type: 'success',
          message: msg
        });
        this.status = '';
      }
    },
    onCancel () {
      this.status = '';
      // 获取用户信息
      this.getUserInfo();
    },
    openPrivacy () {
      if (this.is_xs) {
        this.drawer = true;
      } else {
        this.dialogVisible = true;
      }
    }
  }
}
</script>

<style lang="less" scoped>
  .hager-info-page {
    padding: 2rem 0.5rem 0;
    box-sizing: border-box;
    .input-title {
      color: @secondary-color;
      font-weight: bold;
      font-size: 1.25rem;
      text-align: center;
    }
    .submit-btn {
      background-color: #FFF;
      color: @secondary-color;
      padding: 0.5rem 1rem;
      text-align: center;
      border-radius: 5px;
      border: 1px solid @secondary-color;
      &:hover {
        cursor: pointer;
      }
    }
    .edit-box {
      display: flex;
      justify-content: space-between;
      .cancel {
        margin-right: 1%;
        color: @secondary-color;
      }
      .confirm {
        margin-left: 1%;
        background-color: @secondary-color;
        color: #FFF;
      }
      .btn {
        width: 48%;
        text-align: center;
        padding: 0.5rem 1rem;
        border-radius: 5px;
        border: 1px solid @secondary-color;
        &:hover {
          cursor: pointer;
        }
      }
    }
    .info-footer {
      padding: 0 1rem 1rem 2rem;
      .info-subsidiary {
        display: flex;
        justify-content: space-between;
        font-size: 0.85rem;
        margin-top: 1rem;
        span {
          color: @primary-color;
          text-decoration: underline;
          font-weight: bold;
          &:hover {
            cursor: pointer;
          }
        }
        .privacy {

        }
        .login {

        }
      }
    }
  }
</style>