zhangzengfei
2021-12-17 cf97aba45e50093a6dab045e3a5e0b747076379d
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<template>
  <div class="s-licence">
    <div class="licence" @click="dialogVisible = true">
      <span>{{ tip }}</span>
    </div>
    <el-dialog
      title="授权管理"
      :visible.sync="dialogVisible"
      width="540px"
      :close-on-click-modal="false"
      :before-close="closeDialog"
    >
      <div class="s-dialog">
        <el-tabs v-model="active" v-show="authStatus === 'unregistered'">
          <el-tab-pane label="注册" name="first">
            <el-alert
              title="正式授权绑定"
              type="warning"
              description="请仔细填写以下内容,并保证内容完全属实"
              show-icon
              :closable="false"
              style="text-align:left"
            ></el-alert>
            <br />
            <el-form ref="reginfo" :model="registe" :rules="rules" status-icon label-width="80px">
              <el-form-item label="公司名称" prop="company">
                <el-input v-model="registe.company" size="small" style="max-width:420px"></el-input>
              </el-form-item>
              <el-form-item label="电子邮箱" prop="email">
                <el-input v-model="registe.email" size="small" style="max-width:420px"></el-input>
              </el-form-item>
              <el-form-item label="手机号码" prop="phone">
                <el-input v-model="registe.phone" size="small" style="max-width:420px"></el-input>
              </el-form-item>
              <el-button type="primary" size="small" @click="getRegsiterCode()" style="float:right">提交</el-button>
            </el-form>
          </el-tab-pane>
          <el-tab-pane label="认证" name="second" style="text-align:left" :disabled="!regCode.length">
            <div v-show="!showQrcode" class="auth-box">
              <span style="line-height: 30px;">注册码</span>
              <a href="#" @click="showQrcode = true" style="font-size: 10px;">&nbsp;查看二维码</a>
              <el-input type="textarea" :readonly="true" :rows="4" placeholder v-model="regCode"></el-input>
              <span style="line-height: 30px;">授权码</span>
              <el-input type="textarea" :rows="5" placeholder="请输入授权码" v-model="license"></el-input>
              <el-button type="primary" size="small" @click="submitLicence()" style="margin-top: 15px;float: right;"
                >提交</el-button
              >
            </div>
            <div v-show="showQrcode" style="text-align:right">
              <vue-qrcode :text="regCode" style="margin-left: 115px;"></vue-qrcode>
              <a href="#" @click="showQrcode = false">返回</a>
            </div>
          </el-tab-pane>
        </el-tabs>
        <div class="info" v-show="authStatus === 'registered'">
          <p>
            <b>授权用户</b>
          </p>
          <p>用户名称:{{ registe.company }}</p>
          <p>电子邮箱:{{ registe.email }}</p>
          <p>
            授权期限:{{ registe.expireTime | TimeFormat }}
            <span v-show="expired" style="color:red">已过期</span>
          </p>
          <el-divider></el-divider>
          <p>
            <b>授权码</b>
          </p>
          <el-input type="textarea" :readonly="true" :rows="4" placeholder v-model="licenseCode"></el-input>
          <el-button type="primary" size="small" @click="rereg()" style="margin-top: 15px;float: right;"
            >重新注册</el-button
          >
        </div>
      </div>
    </el-dialog>
  </div>
</template>
 
<script>
import { showLicence, getRegCode, updateLicence } from "./api.ts"
import { isPhone, validEmail } from "../../scripts/validate.ts"
import VueQrcode from "vue-qrcode-component"
 
export default {
  name: "LicenceManage",
  components: {
    VueQrcode
  },
  data() {
    return {
      registe: {
        company: "",
        email: "",
        phone: "",
        expireTime: 0
      },
      dialogVisible: false,
      authStatus: "",
      active: "first",
      regCode: "",
      license: "",
      licenseCode: "",
      expired: false,
      showQrcode: false,
      tip: "",
      rules: {
        email: [
          {
            required: true,
            message: "请输入正确的邮箱地址",
            trigger: "change"
          },
          { validator: validEmail, trigger: "blur" }
        ],
        phone: [
          {
            required: true,
            message: "请输入正确的手机号码",
            trigger: "change"
          },
          { validator: isPhone, trigger: "blur" }
        ],
        company: [
          {
            required: true,
            message: "公司名称不能为空",
            trigger: "change"
          }
        ]
      }
    }
  },
  filters: {
    TimeFormat(timestamp) {
      var now = new Date()
      var currentYear = now.getFullYear()
 
      var date = new Date(timestamp * 1000) //时间戳为10位需*1000,时间戳为13位的话不需乘1000
      var Y = date.getFullYear()
      var M = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1
      var D = date.getDate() < 10 ? "0" + date.getDate() : date.getDate()
 
      if (Y - currentYear > 5) {
        return "永久有效"
      }
 
      return Y + "-" + M + "-" + D
    }
  },
  mounted() {
    this.getLicence()
  },
  methods: {
    closeDialog() {
      this.getLicence()
      this.dialogVisible = false
    },
    async getLicence() {
      let rsp = await showLicence()
      if (rsp && rsp.success) {
        if (rsp.data.License.Expires === 0) {
          this.authStatus = "unregistered"
          this.tip = "未授权, 点击注册"
        } else {
          this.authStatus = "registered"
          this.registe.company = rsp.data.License.RegCode.Company
          this.registe.email = rsp.data.License.RegCode.Email
          this.registe.phone = rsp.data.License.RegCode.Phone
          this.registe.expireTime = rsp.data.License.Expires
          console.log(this.registe.expireTime)
 
          this.licenseCode = rsp.data.License.LicenseCode
          this.expired = rsp.data.Expired
          if (this.expired) {
            this.tip = "授权已过期"
          } else {
            this.tip = "已授权"
          }
        }
      }
      this.showBtn = true
    },
    getRegsiterCode() {
      this.$refs["reginfo"].validate((valid) => {
        if (valid) {
          getRegCode(this.registe).then((rsp) => {
            if (rsp && rsp.success) {
              this.regCode = rsp.data
              this.active = "second"
            }
          })
        }
      })
    },
    submitLicence() {
      updateLicence({ license: this.license })
        .then((rsp) => {
          if (rsp && rsp.success) {
            this.$notify({
              type: "success",
              message: "更新授权成功"
            })
 
            this.authStatus = "registered"
            this.getLicence()
          }
        })
        .catch((err) => {
          this.$notify({
            type: "error",
            message: "授权更新失败"
          })
        })
    },
    rereg() {
      this.active = "first"
      this.authStatus = "unregistered"
    }
  }
}
</script>
<style lang="scss">
.s-licence {
  .licence {
    float: right;
    color: white;
    margin: 15px;
    cursor: pointer;
  }
  .s-dialog {
    width: 500px;
    height: 360px;
  }
 
  .info {
    text-align: left;
    p {
      line-height: 30px;
    }
  }
  textarea {
    resize: none;
  }
}
</style>