Sfoglia il codice sorgente

许可证功能迁移

wy 11 mesi fa
parent
commit
2914fb5c99

+ 6 - 0
src/api/oauth2/oauth2.js

@@ -91,6 +91,7 @@ var OAuth = function(clientId, clientSecret, getToken, saveToken) {
   this.clientId = clientId
   this.clientSecret = clientSecret
   this.statistic =''
+  this.username = ''
   // token的获取和存储
   this.store = {}
   this.getToken = getToken || function(uid, callback) {
@@ -213,12 +214,14 @@ OAuth.prototype.getAuthorizeURLForWebsite = function(redirect, state, scope) {
  * @param {Function} callback 回调函数
  */
 OAuth.prototype.getAccessTokenByCode = function(code, callback) {
+  localStorage.setItem('username', this.username)
   const args = {
     url: OAUTH2_URL() + '/authentication/apply',
     data: {
       client_id: this.clientId,
       client_secret: this.clientSecret,
       authorize_code: code,
+      username: this.username,
       grant_type: 'authorization_code'
     },
     method: 'post'
@@ -297,12 +300,14 @@ OAuth.prototype.getAccessTokenByPassword = function({ username, password }, call
  * @param {Function} callback 回调函数
  */
 OAuth.prototype.refreshAccessToken = function(refreshToken, callback) {
+  const username = localStorage.getItem('username')
   const args = {
     url: OAUTH2_URL() + '/authentication/apply',
     data: {
       client_id: this.clientId,
       client_secret: this.clientSecret,
       grant_type: 'refresh_token',
+      username,
       refresh_token: refreshToken
     },
     method: 'post'
@@ -534,6 +539,7 @@ OAuth.prototype.getUserByCode = function(options, callback) {
  * @param {*} callback
  */
 OAuth.prototype.getLoginCode = function(options, callback) {
+  this.username = options.username
   const that = this
   /**
    * 用户登录

+ 13 - 0
src/api/oauth2/user.js

@@ -218,4 +218,17 @@ export function open () {
         url: OAUTH2_URL() + '/user/open/tenant',
         method: 'get'
     })
+}
+
+/**
+ * 更新许可证
+ * @param {String} username 用户名
+ * @param {String} licence 许可证
+ */
+export function updateLicence (params) {
+    return request({
+        url: OAUTH2_URL() + '/authentication/updateLicense',
+        method: 'post',
+        data: params
+    })
 }

+ 23 - 0
src/layout/header-aside/components/header-message/index.vue

@@ -116,6 +116,29 @@ export default {
     //     this.loadData()
     // }, 1000)
     // Watermark.set('线上试用版本','深圳市金源信通')
+    const { licence = {} } = this.$store.getters
+    const { isTrialVersion, notAfter, needRemind, customerInfo } = licence
+    const now = Date.now()
+    if (isTrialVersion) {
+            // 超出试用期限后登出
+            if (now > notAfter) {
+                this.$store.dispatch('ibps/account/logout', {
+                    vm: this
+                })
+                return
+            }
+            if (needRemind) {
+                this.$confirm('系统试用期即将结束,请联系开发方购买永久版或申请新的试用许可证!', '提示', {
+                    type: 'warning',
+                    showCancelButton: false,
+                    showClose: false,
+                    closeOnClickModal: false
+                })
+            }
+            const limitDate = new Date(notAfter).toLocaleDateString('zh-CN')
+            const temp = customerInfo && customerInfo.length >= 12 ? customerInfo : `${customerInfo}试用版本`
+            Watermark.set(`${temp}`, `试用日期截止至${limitDate}`)
+        }
     this.loadData()
     Bus.$on('getMessageCount', (count) => {
       this.messageCount = count

+ 2 - 0
src/store/modules/ibps/modules/user.js

@@ -57,6 +57,8 @@ export default {
                 await dispatch('getAccount')
                 // 获取切换用户账号
                 await dispatch('getSwitchAccount')
+                // 存储许可证信息
+                await dispatch('ibps/licence/setLicence', JSON.parse(localStorage.getItem('licence')), { root: true })
 
                 // 获取注册用户账号
                 dispatch('getRegister').then((r) => {

+ 10 - 4
src/utils/encrypt.js

@@ -1,9 +1,13 @@
 import CryptoJS from 'crypto-js'
-const key = CryptoJS.enc.Utf8.parse('dmngJmmO+9GMw+tu')
-const iv = CryptoJS.enc.Utf8.parse('sanXyqhk8+U7LPP4')
+const key1 = CryptoJS.enc.Utf8.parse('dmngJmmO+9GMw+tu')
+const iv1 = CryptoJS.enc.Utf8.parse('sanXyqhk8+U7LPP4')
+const key2 = CryptoJS.enc.Utf8.parse('49PBou+TREIOzSHj')
+const iv2 = CryptoJS.enc.Utf8.parse('5lDsNRe&UduJ97uS')
 // AES加密
-export const encryptByAes = pwd => {
+export const encryptByAes = (pwd, type = 'normal') => {
     let encrypted = ''
+    const key = type === 'normal' ? key1 : key2
+    const iv = type === 'normal' ? iv1 : iv2
     if (typeof pwd === 'string') {
         const srcs = CryptoJS.enc.Utf8.parse(pwd)
         const options = {
@@ -25,7 +29,9 @@ export const encryptByAes = pwd => {
     return encrypted.ciphertext.toString(CryptoJS.enc.Base64)
 }
 
-export const decryptByAes = encryptedText => {
+export const decryptByAes = (encryptedText, type = 'normal') => {
+    const key = type === 'normal' ? key1 : key2
+    const iv = type === 'normal' ? iv1 : iv2
     const options = {
         iv: iv,
         mode: CryptoJS.mode.CBC, // 使用CBC模式

+ 148 - 0
src/views/system/licence/index.vue

@@ -0,0 +1,148 @@
+<template>
+    <ibps-container
+        type="full"
+        header-background-color
+        class="licence"
+    >
+        <div class="licence-container">
+            <div class="title">
+                <span>许可证信息</span>
+                <span>{{ `(${licence.isTrialVersion ? '试用版' : '正式版'})` }}</span>
+                <el-button
+                    v-if="licence.isTrialVersion"
+                    type="success"
+                    size="mini"
+                    @click="licenceFormVisible = true"
+                ><i class="el-icon-refresh el-icon--left" />更新</el-button>
+            </div>
+            <div class="card">
+                <div class="item">
+                    <div class="label">单位名称</div>
+                    <div class="value">{{ licence.customerInfo }}</div>
+                </div>
+                <div class="item">
+                    <div class="label">发布时间</div>
+                    <div class="value">{{ transformDate(licence.issuedTime) }}</div>
+                </div>
+                <div class="item">
+                    <div class="label">生效时间</div>
+                    <div class="value">{{ transformDate(licence.notBefore) }}</div>
+                </div>
+                <template v-if="licence.isTrialVersion">
+                    <div class="item">
+                        <div class="label">失效时间</div>
+                        <div class="value">{{ transformDate(licence.notAfter) }}</div>
+                    </div>
+                    <div class="item">
+                        <div class="label">到期提醒天数</div>
+                        <div class="value">{{ licence.reminderDays }}</div>
+                    </div>
+                </template>
+                <div class="item">
+                    <div class="label">状态</div>
+                    <div class="value">
+                        <el-tag :type="state"> {{ status[state] }} </el-tag>
+                    </div>
+                </div>
+            </div>
+        </div>
+        <update-licence
+            :visible="licenceFormVisible"
+            :username="account"
+            @close="visible => licenceFormVisible = visible"
+        />
+    </ibps-container>
+</template>
+<script>
+
+export default {
+    components: {
+        updateLicence: () => import('@/views/system/licence/update')
+    },
+    data () {
+        const { account = '', licence = {}} = this.$store.getters
+        return {
+            licenceFormVisible: false,
+            account,
+            licence,
+            status: {
+                success: '正常',
+                warning: '即将到期',
+                danger: '过期'
+            }
+        }
+    },
+    computed: {
+        state () {
+            const { isTrialVersion, needRemind, overtime } = this.licence || {}
+            if (!isTrialVersion) {
+                return 'success'
+            }
+            if (overtime) {
+                return 'danger'
+            }
+            if (needRemind) {
+                return 'warning'
+            }
+            return 'success'
+        }
+    },
+    mounted () {
+        console.log(this.licence)
+    },
+    methods: {
+        handUpdate () {
+            this.licenceFormVisible = true
+        },
+        transformDate (v) {
+            return v ? new Date(v).toLocaleString('zh-CN', { hour12: false }).replace(/\//g, '-') : ''
+        }
+    }
+}
+</script>
+<style lang="scss" scoped>
+.licence-container {
+    width: 1080px;
+    margin: 20px auto;
+    height: calc(100% - 100px);
+    padding: 20px;
+    border: 1px solid #ccc;
+    border-radius: 10px;
+    background-color: #f9f9f9;
+    box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
+    transition: transform 0.2s;
+    .title {
+        font-size: 24px;
+        font-weight: bold;
+        margin-bottom: 20px;
+        display: flex;
+        align-items: center;
+    }
+    .card {
+        display: flex;
+        flex-wrap: wrap;
+        justify-content: space-between;
+        .item {
+            width: 100%;
+            margin-bottom: 20px;
+            padding: 15px;
+            border: 1px solid #ccc;
+            border-radius: 5px;
+            background-color: #fff;
+            transition: transform 0.2s;
+            &:hover {
+                transform: scale(1.01);
+            }
+            .label {
+                font-size: 16px;
+                font-weight: bold;
+                margin-bottom: 10px;
+            }
+            .value {
+                font-size: 16px;
+                color: #666;
+            }
+        }
+    }
+}
+</style>

+ 225 - 0
src/views/system/licence/indexCopy.vue

@@ -0,0 +1,225 @@
+<template>
+    <ibps-container
+        type="full"
+        header-background-color
+        class="licence"
+    >
+        <ibps-crud
+            ref="crud"
+            display-field="系统许可证"
+            :height="tableHeight"
+            :data="listData"
+            :toolbars="listConfig.toolbars"
+            :pk-key="pkKey"
+            :columns="listConfig.columns"
+            :pagination="pagination"
+            :row-handle="rowHandle"
+            :loading="loading"
+            style="width:100%;"
+            @action-event="handleAction"
+            @pagination-change="handlePaginationChange"
+        />
+        <update-licence
+            :visible="licenceFormVisible"
+            :username="account1"
+            @close="visible => licenceFormVisible = visible"
+        />
+    </ibps-container>
+
+</template>
+<script>
+import ActionUtils from '@/utils/action'
+export default {
+    components: {
+        updateLicence: () => import('@/views/system/licence/update')
+    },
+    props: {
+        height: {
+            type: String,
+            default: '400px'
+        }
+    },
+    data () {
+        const { account = '', licence = {}} = this.$store.getters
+        return {
+            licenceFormVisible: false,
+            account1:'',
+            licence,
+            pkKey: 'id', // 主键  如果主键不是pk需要传主键
+            status: {
+                success: '正常',
+                warning: '即将到期',
+                danger: '过期'
+            },
+            loading: false,
+            listConfig: {
+                // 工具栏
+                toolbars: [
+                    { key: 'search' }
+                ],
+                // 查询条件
+                // searchForm: {
+                //     labelWidth: 100,
+                //     forms: [
+                //         { prop: 'Q^APP_KEY_^SL', label: '应用标识', fieldType: 'slot', slotName: 'appKey' },
+                //         { prop: 'Q^API_KEY_^SL', label: '接口标识' },
+                //         { prop: 'Q^API_NAME_^SL', label: '接口名称' },
+                //         { prop: 'Q^API_URI_^SL', label: '接口地址' }
+                //     ]
+                // },
+                // 表格字段配置
+                columns: [
+                    { prop: 'isTrialVersion', label: '许可证信息' },
+                    { prop: 'customerInfo', label: '单位名称', minWidth: 200 },
+                    { prop: 'issuedTime', label: '发布时间', width: 120 },
+                    { prop: 'notBefore', label: '生效时间', width: 120 },
+                    { prop: 'notAfter', label: '失效时间', width: 120 },
+                    { prop: 'reminderDays', label: '到期提醒天数', width: 120 },
+                    { prop: 'status', label: '状态' }
+                ]
+            },
+            listData: [
+                {
+                    id: '1',
+                    isTrialVersion: '许可证信息',
+                    customerInfo: '单位名称',
+                    issuedTime: '2024-01-01',
+                    notBefore: '2024-01-01',
+                    notAfter: '2024-01-01',
+                    reminderDays: '到期提醒天数',
+                    status: '状态'
+                }
+            ],
+            pagination: {},
+            rowHandle: {
+                actions: [
+                    {
+                        $index: 1,
+                        key: 'edit',
+                        button_type: 'detail',
+                        label: '更新',
+                        icon: 'ibps-icon-edit',
+                        type: 'primary',
+                        deflow: null,
+                        isEditOnHis: false,
+                        initAddDataCont: null,
+                        disabled: false,
+                        hidden: false,
+                        position: 'manage'
+                    }
+                ],
+                effect: 'display'
+
+            }
+        }
+    },
+    computed: {
+        state () {
+            const { isTrialVersion, needRemind, overtime } = this.licence || {}
+            if (!isTrialVersion) {
+                return 'success'
+            }
+            if (overtime) {
+                return 'danger'
+            }
+            if (needRemind) {
+                return 'warning'
+            }
+            return 'success'
+        },
+        tableHeight () {
+            const h = this.height.substr(0, this.height.length - 2)
+            return parseInt(h) - 10
+        }
+    },
+    mounted () {
+        this.loadData()
+    },
+    methods: {
+        loadData () {
+            console.log('91 this.licence', this.licence)
+        },
+        handUpdate () {
+            this.licenceFormVisible = true
+        },
+        transformDate (v) {
+            return v ? new Date(v).toLocaleString('zh-CN', { hour12: false }).replace(/\//g, '-') : ''
+        },
+        /**
+     * 处理按钮事件
+     */
+        handleAction (command, position, selection, data) {
+            switch (command) {
+                case 'search':// 查询
+                    ActionUtils.setFirstPagination(this.pagination)
+                    this.search()
+                    break
+                case 'edit':// 编辑许可证信息
+                    this.editLicence()
+                    break
+                default:
+                    break
+            }
+        },
+        /**
+         * 处理分页事件
+         */
+        handlePaginationChange (page) {
+            ActionUtils.setPagination(this.pagination, page)
+            this.loadData()
+        },
+        search () {
+
+        },
+        editLicence () {
+            this.licenceFormVisible = true
+        }
+    }
+}
+</script>
+<style lang="scss" scoped>
+// .licence-container {
+//     width: 1080px;
+//     margin: 20px auto;
+//     height: calc(100% - 100px);
+//     padding: 20px;
+//     border: 1px solid #ccc;
+//     border-radius: 10px;
+//     background-color: #f9f9f9;
+//     box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
+//     transition: transform 0.2s;
+//     .title {
+//         font-size: 24px;
+//         font-weight: bold;
+//         margin-bottom: 20px;
+//         display: flex;
+//         align-items: center;
+//     }
+//     .card {
+//         display: flex;
+//         flex-wrap: wrap;
+//         justify-content: space-between;
+//         .item {
+//             width: 100%;
+//             margin-bottom: 20px;
+//             padding: 15px;
+//             border: 1px solid #ccc;
+//             border-radius: 5px;
+//             background-color: #fff;
+//             transition: transform 0.2s;
+//             &:hover {
+//                 transform: scale(1.01);
+//             }
+//             .label {
+//                 font-size: 16px;
+//                 font-weight: bold;
+//                 margin-bottom: 10px;
+//             }
+//             .value {
+//                 font-size: 16px;
+//                 color: #666;
+//             }
+//         }
+//     }
+// }
+</style>

+ 143 - 0
src/views/system/licence/update.vue

@@ -0,0 +1,143 @@
+<template>
+    <el-dialog
+        :title="title"
+        :visible.sync="dialogVisible"
+        :close-on-click-modal="false"
+        :close-on-press-escape="false"
+        append-to-body
+        class="licence-dialog"
+        @close="closeDialog"
+    >
+        <el-form
+            ref="updateLicence"
+            v-loading="dialogLoading"
+            :model="formModel"
+            :rules="rules"
+            :element-loading-text="$t('common.loading')"
+            :label-width="formLabelWidth"
+            @submit.native.prevent
+        >
+            <el-form-item prop="licenceKey">
+                <el-input
+                    ref="input"
+                    v-model="formModel.licenceKey"
+                    type="textarea"
+                    rows="8"
+                    maxlength="4000"
+                    show-word-limit
+                    required
+                    placeholder="请填写开发方提供的许可证"
+                />
+            </el-form-item>
+        </el-form>
+        <div slot="footer" class="el-dialog--center">
+            <ibps-toolbar
+                :actions="toolbars"
+                @action-event="handleActionEvent"
+            />
+        </div>
+    </el-dialog>
+</template>
+
+<script>
+import { updateLicence } from '@/api/oauth2/user'
+export default {
+    props: {
+        visible: {
+            type: Boolean,
+            default: false
+        },
+        title: {
+            type: String,
+            default: '更新许可证'
+        },
+        username: {
+            type: String,
+            default: ''
+        }
+    },
+    data () {
+        return {
+            formName: 'updateLicence',
+            formLabelWidth: '0px',
+            dialogVisible: this.visible,
+            dialogLoading: false,
+            formModel: {
+                licenceKey: ''
+            },
+            rules: {
+                licenceKey: [
+                    {
+                        required: true,
+                        message: this.$t('validate.required')
+                    }
+                ]
+            },
+            toolbars: [
+                { key: 'save', label: '更新' },
+                { key: 'cancel' }
+            ]
+        }
+    },
+    watch: {
+        visible: {
+            handler: function (val, oldVal) {
+                this.dialogVisible = this.visible
+            },
+            immediate: true
+        }
+    },
+    methods: {
+        handleActionEvent ({ key }) {
+            switch (key) {
+                case 'save':
+                    this.handleSave()
+                    break
+                case 'cancel':
+                    this.closeDialog()
+                    break
+                default:
+                    break
+            }
+        },
+        // 保存数据
+        handleSave () {
+            this.$refs[this.formName].validate(valid => {
+                if (valid) {
+                    this.saveData()
+                } else {
+                    this.$message.warning('请填写开发方提供的许可证信息!')
+                }
+            })
+        },
+        // 提交保存数据
+        saveData () {
+            updateLicence({
+                username: this.username,
+                license: this.formModel.licenceKey
+            }).then(res => {
+                console.log(res)
+                this.$message.success('更新许可证成功,请重新登录!')
+                this.closeDialog()
+            })
+        },
+        // 关闭当前窗口
+        closeDialog () {
+            this.$emit('close', false)
+            this.$refs[this.formName].resetFields()
+        }
+    }
+}
+</script>
+<style lang="scss" scoped>
+    .licence-dialog {
+        ::v-deep .el-dialog {
+            margin-top: calc((100vh - 288px) / 2.5) !important;
+            .el-dialog__body {
+                .el-form {
+                    padding: 10px;
+                }
+            }
+        }
+    }
+</style>

+ 379 - 294
src/views/system/login/user-login.vue

@@ -9,7 +9,7 @@
         label-width="80"
         @submit.native.prevent
     >
-        <br/>
+        <br>
         <el-form-item label="账号" prop="username">
             <el-input
                 v-model="loginForm.username"
@@ -17,8 +17,8 @@
                 tabindex="1"
                 auto-complete="on"
                 prefix-icon="ibps-icon-user"
-                @keyup.enter.native="handleLogin"
                 style="width:75%;"
+                @keyup.enter.native="handleLogin"
             />
         </el-form-item>
         <el-tooltip
@@ -45,7 +45,7 @@
                         :class="passwordType === 'password' ? 'ibps-icon-eye-slash' : 'ibps-icon-eye'"
                         class="el-input__icon"
                         @click="showPassword"
-                    ></i>
+                    />
                 </el-input>
             </el-form-item>
         </el-tooltip>
@@ -64,20 +64,20 @@
                 </el-col>
                 <el-col :span="9">
                     <div class="login-code">
-                        <span v-if="code.type === 'text'" class="login-code-img" @click="refreshCode">{{ code.value}}</span>
+                        <span v-if="code.type === 'text'" class="login-code-img" @click="refreshCode">{{ code.value }}</span>
                         <img v-else :src="code.src" class="login-code-img" @click="refreshCode">
                     </div>
                 </el-col>
             </el-row>
         </el-form-item>
-        <el-form-item prop="remember">
+        <!-- <el-form-item prop="remember">
             <el-row :span="24">
                 <el-col :span="14">
                     <el-checkbox v-model="loginForm.remember">{{ $t('login.remember') }}</el-checkbox>
                 </el-col>
                 <el-col v-if="isRegOpen || isTenantOpen" :span="10">
                     <el-button
-                        v-if="!isTenantOpen"
+                        v-if="!isTenantOpen"    
                         type="text"
                         class="forget"
                         @click="forget"
@@ -104,326 +104,411 @@
                     >{{ $t('login.tenantRegister') }}</el-button>
                 </el-col>
             </el-row>
-        </el-form-item>
-        <br/>
-        <el-form-item>
-            <el-button
-                :loading="loading"
-                type="primary"
-                class="login-submit"
-                @click.native.prevent="handleLogin"
-            >{{ $t('login.logIn') }}</el-button>
-        </el-form-item>
+        </el-form-item> -->
+        <el-button
+            :loading="loading"
+            type="primary"
+            class="login-submit"
+            @click.native.prevent="handleLogin"
+        >{{ $t('login.logIn') }}</el-button>
+        <update-licence
+            :visible="licenceFormVisible"
+            :username="loginForm.username"
+            @close="visible => licenceFormVisible = visible"
+        />
     </el-form>
 </template>
 
 <script>
-    import { mapActions } from 'vuex'
-    import Utils from '@/utils/util'
-    import I18n from '@/utils/i18n'
-    import { SZG_getServerCertificate, SZG_genRandom, SZG_signData } from '@/api/oauth2/ca'
-    // import './xtxsync'
-    const loginForm = process.env.NODE_ENV === 'development'
-        ? {
-            username: 'jinyuan',
-            password: 'szjbd168',
-            captcha: '',
-            remember: true,
-            requestId: ''
-        } : {
-            username: '',
-            password: '',
-            captcha: '',
-            remember: true,
-            requestId: ''
-        }
+import { mapActions } from 'vuex'
+import Utils from '@/utils/util'
+import I18n from '@/utils/i18n'
+import { encryptByAes } from '@/utils/encrypt'
+import { SZG_getServerCertificate, SZG_genRandom, SZG_signData } from '@/api/oauth2/ca'
+// import './xtxsync'
+const loginForm = process.env.NODE_ENV === 'development'
+    ? {
+        username: 'jinyuan',
+        password: 'szjbd168',
+        captcha: '',
+        remember: true,
+        requestId: ''
+    } : {
+        username: '',
+        password: '',
+        captcha: '',
+        remember: true,
+        requestId: ''
+    }
 
-    const validateUsername = (rule, value, callback) => {
-        if (Utils.isEmpty(value)) {
-            return callback(new Error(I18n.t('login.usernameCorrect')))
-        }
-        callback()
+const validateUsername = (rule, value, callback) => {
+    if (Utils.isEmpty(value)) {
+        return callback(new Error(I18n.t('login.usernameCorrect')))
     }
-    const validateMobile = (rule, value, callback) => {
-        if (Utils.isEmpty(value)) {
-            return callback(new Error(I18n.t('手机号不能为空')))
+    callback()
+}
+const validateMobile = (rule, value, callback) => {
+    if (Utils.isEmpty(value)) {
+        return callback(new Error(I18n.t('手机号不能为空')))
+    } else {
+        const isPhone = /^1(3|4|5|6|7|8|9)\d{9}$/
+        if (value.length === 11) {
+            if (!isPhone.test(value)) {
+                return callback(new Error(I18n.t('请输入正确手机号')))
+            } else {
+                callback()
+            }
         } else {
-            const isPhone = /^1(3|4|5|6|7|8|9)\d{9}$/
-            if (value.length === 11) {
-                if (!isPhone.test(value)) {
-                    return callback(new Error(I18n.t('请输入正确手机号')))
-                } else {
-                    callback()
-                }
+            if (!isPhone.test(value)) {
+                return callback(new Error(I18n.t('请输入正确手机号')))
             } else {
-                if (!isPhone.test(value)) {
-                    return callback(new Error(I18n.t('请输入正确手机号')))
-                } else {
-                    return callback(new Error(I18n.t('请输入正确手机号长度')))
-                }
+                return callback(new Error(I18n.t('请输入正确手机号长度')))
             }
         }
     }
-    const validateCode = (rule, value, callback) => {
-        callback()
-        // if (this.code.value !== value) {
-        //   this.loginForm.captcha = ''
-        //   this.loadValidCode(false)
-        //   callback(new Error(I18n.t('login.codeCorrect')))
-        // } else {
-        //   callback()
-        // }
-    }
+}
+const validateCode = (rule, value, callback) => {
+    callback()
+    // if (this.code.value !== value) {
+    //   this.loginForm.captcha = ''
+    //   this.loadValidCode(false)
+    //   callback(new Error(I18n.t('login.codeCorrect')))
+    // } else {
+    //   callback()
+    // }
+}
 
-    export default {
-        name: 'login-form',
-        data () {
-            return {
-                demoVar: '123',
-                enabledValidCode: false,
-                loginForm,
-                isRegOpen: false,
-                isTenantOpen: false,
-                validateMobile: validateMobile,
-                code: {
-                    src: '',
-                    value: '',
-                    len: 5,
-                    type: 'src'
-                },
-                loginRules: {
-                    username: [
-                        {
-                            required: true,
-                            trigger: 'blur',
-                            message: this.$t('login.usernameCorrect'),
-                            validator: validateUsername
-                        }
-                    ],
-                    password: [
-                        {
-                            required: true,
-                            message: this.$t('login.password'),
-                            trigger: 'blur'
-                        },
-                        {
-                            min: 1,
-                            message: this.$t('login.passwordCorrect'),
-                            trigger: 'blur'
-                        }
-                    ],
-                    captcha: [
-                        {
-                            required: true,
-                            message: this.$t('login.code'),
-                            trigger: 'blur'
-                        },
-                        {
-                            required: true,
-                            trigger: 'blur',
-                            validator: validateCode
-                        }
-                    ]
+export default {
+    name: 'login-form',
+     components: {
+        updateLicence: () => import('@/views/system/licence/update')
+    },
+    data () {
+        return {
+            demoVar: '123',
+            enabledValidCode: false,
+            loginForm,
+            isRegOpen: false,
+            isTenantOpen: false,
+            validateMobile: validateMobile,
+            code: {
+                src: '',
+                value: '',
+                len: 5,
+                type: 'src'
+            },
+            loginRules: {
+                username: [
+                    {
+                        required: true,
+                        trigger: 'blur',
+                        message: this.$t('login.usernameCorrect'),
+                        validator: validateUsername
+                    }
+                ],
+                password: [
+                    {
+                        required: true,
+                        message: this.$t('login.password'),
+                        trigger: 'blur'
+                    },
+                    {
+                        min: 1,
+                        message: this.$t('login.passwordCorrect'),
+                        trigger: 'blur'
+                    }
+                ],
+                captcha: [
+                    {
+                        required: true,
+                        message: this.$t('login.code'),
+                        trigger: 'blur'
+                    },
+                    {
+                        required: true,
+                        trigger: 'blur',
+                        validator: validateCode
+                    }
+                ]
 
-                },
-                passwordType: 'password',
-                capsTooltip: false,
-                loading: false
+            },
+            passwordType: 'password',
+            capsTooltip: false,
+            loading: false
+        }
+    },
+    watch: {
+        isRegOpen: {
+            handler: function (val, oldVal) {
+                if (val) {
+                    this.loginRules.username = [{
+                        required: true,
+                        trigger: 'blur',
+                        validator: validateMobile
+                    }]
+                } else {
+                    this.loginRules.username = [{
+                        required: true,
+                        trigger: 'blur',
+                        validator: validateUsername
+                    }]
+                }
+            },
+            immediate: true
+        }
+    },
+    created () {
+        this.initValidCode()
+        this.loadValidCode(true)
+        this.isRegisterOpen()
+    },
+    mounted () {
+        // 注销退出清空验证码
+        this.loginForm.captcha = ''
+        // 注销退出清空请求ID
+        this.loginForm.requestId = ''
+    },
+    methods: {
+        ...mapActions({
+            'login': 'ibps/account/login',
+            'getCaptcha': 'ibps/account/getCaptcha',
+            'getRegisterOpen': 'ibps/account/getRegisterOpen',
+            'getRegisterTenantOpen': 'ibps/saas/getRegisterTenantOpen'
+        }),
+        initValidCode () {
+            if (this.enabledValidCode) {
+                this.loginRules.captcha[0]['required'] = true
+                this.loginRules.captcha[1]['required'] = true
+            } else {
+                this.loginRules.captcha[0]['required'] = false
+                this.loginRules.captcha[1]['required'] = false
             }
         },
-        watch: {
-            isRegOpen: {
-                handler: function (val, oldVal) {
-                    if (val) {
-                        this.loginRules.username = [{
-                            required: true,
-                            trigger: 'blur',
-                            validator: validateMobile
-                        }]
-                    } else {
-                        this.loginRules.username = [{
-                            required: true,
-                            trigger: 'blur',
-                            validator: validateUsername
-                        }]
-                    }
-                },
-                immediate: true
-            }
+        isRegisterOpen () {
+            this.getRegisterOpen().then((data) => {
+                this.isRegOpen = data.data
+            }).catch((e) => { })
+            this.getRegisterTenantOpen().then((data) => {
+                this.isTenantOpen = data.data
+            }).catch((e) => { })
         },
-        created () {
-            this.initValidCode()
-            this.loadValidCode(true)
-            this.isRegisterOpen()
+        // 获取验证码
+        loadValidCode (isBackfill) {
+            this.getCaptcha({ params: { requestId: this.loginForm.requestId }}).then((data) => {
+                // 返回状态501,说明系统没有开启验证码
+                if (data.state === 501) {
+                    this.enabledValidCode = false
+                } else {
+                    this.enabledValidCode = true
+                    this.code.src = data.data
+                    this.loginForm.requestId = data.variables.requestId
+                }
+                this.initValidCode()
+                if (isBackfill) {
+                    this.loginForm.code = this.code.value
+                }
+            }).catch((e) => {
+
+            })
         },
-        mounted () {
-            // 注销退出清空验证码
-            this.loginForm.captcha = ''
-            // 注销退出清空请求ID
-            this.loginForm.requestId = ''
+        refreshCode () {
+            this.loadValidCode()
         },
-        methods: {
-            ...mapActions({
-                'login': 'ibps/account/login',
-                'getCaptcha': 'ibps/account/getCaptcha',
-                'getRegisterOpen': 'ibps/account/getRegisterOpen',
-                'getRegisterTenantOpen': 'ibps/saas/getRegisterTenantOpen'
-            }),
-            initValidCode () {
-                if (this.enabledValidCode) {
-                    this.loginRules.captcha[0]['required'] = true
-                    this.loginRules.captcha[1]['required'] = true
+        checkCapslock ({ shiftKey, key } = {}) {
+            if (key && key.length === 1) {
+                if ((shiftKey && (key >= 'a' && key <= 'z')) || (!shiftKey && (key >= 'A' && key <= 'Z'))) {
+                    this.capsTooltip = true
                 } else {
-                    this.loginRules.captcha[0]['required'] = false
-                    this.loginRules.captcha[1]['required'] = false
+                    this.capsTooltip = false
                 }
-            },
-            isRegisterOpen () {
-                this.getRegisterOpen().then((data) => {
-                    this.isRegOpen = data.data
-                }).catch((e) => { })
-                this.getRegisterTenantOpen().then((data) => {
-                    this.isTenantOpen = data.data
-                }).catch((e) => { })
-            },
-            // 获取验证码
-            loadValidCode (isBackfill) {
-                this.getCaptcha({ params: { requestId: this.loginForm.requestId } }).then((data) => {
-                    // 返回状态501,说明系统没有开启验证码
-                    if (data.state === 501) {
-                        this.enabledValidCode = false
+            }
+            if (key === 'CapsLock' && this.capsTooltip === true) {
+                this.capsTooltip = false
+            }
+        },
+        showPassword () {
+            this.passwordType === '' ? (this.passwordType = 'password') : (this.passwordType = '')
+        },
+        forget () {
+            this.$router.replace('/forget')
+        },
+        tenantForget () {
+            this.$router.replace('/tenantForget')
+        },
+        register () {
+            this.$router.replace('/register')
+        },
+        tenantRegister () {
+            this.$router.replace('/tenantRegister')
+        },
+        handleLogin () {
+            this.$refs.loginForm.validate(valid => {
+                if (!valid) {
+                    this.$message.closeAll()
+                    this.$message({
+                        message: this.$t('common.dialog.saveError'),
+                        type: 'warning'
+                    })
+                    return false
+                }
+                this.loading = true
+                const loading = this.$loading({
+                    lock: true,
+                    text: this.$t('common.loading'),
+                    background: 'rgba(0, 0, 0, 0.7)'
+                })
+                const submitData = structuredClone(this.loginForm)
+                submitData.password = encryptByAes(submitData.password, 'pwd')
+                // this.login({ form: submitData }).then(data => {
+                //     console.log(1)
+                //     localStorage.setItem('statistic', data.statistic)
+                //     console.log(2)
+                //     // 更新路由 尝试去获取 cookie 里保存的需要重定向的页面完整地址
+                //     const redirect = this.$route.query.redirect
+                //     console.log(data)
+                //     const { overtime } = data.licenceData
+                //     console.log(4)
+                //     if (overtime) {
+                //         this.$message.error('许可证不在使用期限!请更新')
+                //         // 许可证过期,前台登出
+                //         this.$store.dispatch('ibps/account/fedLogout').then(() => {
+                //             this.licenceFormVisible = true
+                //             this.loading = false
+                //             loading.close()
+                //         })
+                //     } else {
+                //         this.$router.replace('/dashboard')
+                //         // 延迟1秒关闭遮盖层
+                //         setTimeout(() => {
+                //             this.loading = false
+                //             loading.close()
+                //         }, 1000)
+                //     }
+                // })
+                this.login({ form: submitData }).then(data => {
+                    console.log('Full response data:', data);
+                    localStorage.setItem('statistic', data.statistic);
+                    
+                    // 更安全的获取 overtime 的方式
+                    const overtime = data?.licenceData?.overtime || false;
+                    if (overtime) {
+                        this.$message.error('许可证不在使用期限!请更新');
+                        this.$store.dispatch('ibps/account/fedLogout').then(() => {
+                            this.licenceFormVisible = true;
+                            this.loading = false;
+                            loading.close();
+                        });
                     } else {
+                        this.$router.replace('/dashboard');
+                        setTimeout(() => {
+                            this.loading = false;
+                            loading.close();
+                        }, 1000);
+                    }
+                }).catch((err) => {
+                    if (err && err.state === 6020203) {
+                        // 许可证过期,前台登出
+                        this.$store.dispatch('ibps/account/fedLogout').then(() => {
+                            this.licenceFormVisible = true
+                        })
+                    }
+                    // 验证码错误自动清空&密码输入错误5次后触发验证码填写模块
+                    if (err && err.state === 6020104) {
+                        this.loginForm.captcha = ''
                         this.enabledValidCode = true
-                        this.code.src = data.data
-                        this.loginForm.requestId = data.variables.requestId
+                        this.refreshCode()
                     }
-                    this.initValidCode()
-                    if (isBackfill) {
-                        this.loginForm.code = this.code.value
+                    // 有错误状态开启验证码需要刷新验证码
+                    if (err && err.state && this.enabledValidCode) {
+                        this.loginForm.captcha = ''
+                        this.refreshCode()
                     }
-                }).catch((e) => {
-
+                    this.loading = false
+                    loading.close()
                 })
-            },
-            refreshCode () {
-                this.loadValidCode()
-            },
-            checkCapslock ({ shiftKey, key } = {}) {
-                if (key && key.length === 1) {
-                    if ((shiftKey && (key >= 'a' && key <= 'z')) || (!shiftKey && (key >= 'A' && key <= 'Z'))) {
-                        this.capsTooltip = true
-                    } else {
-                        this.capsTooltip = false
-                    }
-                }
-                if (key === 'CapsLock' && this.capsTooltip === true) {
-                    this.capsTooltip = false
-                }
-            },
-            showPassword () {
-                this.passwordType === '' ? (this.passwordType = 'password') : (this.passwordType = '')
-            },
-            forget () {
-                this.$router.replace('/forget')
-            },
-            tenantForget () {
-                this.$router.replace('/tenantForget')
-            },
-            register () {
-                this.$router.replace('/register')
-            },
-            tenantRegister () {
-                this.$router.replace('/tenantRegister')
-            },
-            handleLogin () {
-                this.$refs.loginForm.validate(valid => {
-                    if (valid) {
-                        this.loading = true
-                        const loading = this.$loading({
-                            lock: true,
-                            text: this.$t('common.loading'),
-                            background: 'rgba(0, 0, 0, 0.7)'
-                        })
-                        this.login({
-                            form: this.loginForm
-                        }).then((data) => {
-                            localStorage.setItem('statistic', data.statistic)
-                            // 更新路由 尝试去获取 cookie 里保存的需要重定向的页面完整地址
-                            const redirect = this.$route.query.redirect
 
-                            if (redirect && redirect !== '/refresh') {
-                              if(data && (data.statistic === 'isMaster' ||data.statistic === 'isCharger')){
-                                    // 重定向到开始路径
-                                    this.$router.replace('/dashboard')
-                                } else {
-                                    this.$router.replace('/')
-                                }
-                            } else {
-                               if(data && (data.statistic === 'isMaster' ||data.statistic === 'isCharger')){
-                                    // 重定向到开始路径
-                                    this.$router.replace('/dashboard')
-                                } else {
-                                    this.$router.replace('/')
-                                }
-                            }
+                // if (valid) {
 
-                            // 延迟10秒关闭遮盖层
-                            setTimeout(() => {
-                                this.loading = false
-                                loading.close()
-                            }, 1000)
-                        }).catch((err) => {
-                            // 验证码错误自动清空&密码输入错误3次后触发验证码填写模块
-                            if (err && err.state === 6020104) {
-                                this.loginForm.captcha = ''
-                                this.enabledValidCode = true
-                                this.refreshCode()
-                            }
-                            // 有错误状态开启验证码需要刷新验证码
-                            if (err && err.state && this.enabledValidCode) {
-                                this.loginForm.captcha = ''
-                                this.refreshCode()
-                            }
-                            this.loading = false
-                            loading.close()
-                        })
-                    } else {
-                        this.$message.closeAll()
-                        this.$message({
-                            message: this.$t('common.dialog.saveError'),
-                            type: 'warning'
+                //     this.login({
+                //         form: this.loginForm
+                //     }).then((data) => {
+                //         localStorage.setItem('statistic', data.statistic)
+                //         // 更新路由 尝试去获取 cookie 里保存的需要重定向的页面完整地址
+                //         const redirect = this.$route.query.redirect
+
+                //         if (redirect && redirect !== '/refresh') {
+                //             if(data && (data.statistic === 'isMaster' ||data.statistic === 'isCharger')){
+                //                 // 重定向到开始路径
+                //                 this.$router.replace('/dashboard')
+                //             } else {
+                //                 this.$router.replace('/')
+                //             }
+                //         } else {
+                //             if(data && (data.statistic === 'isMaster' ||data.statistic === 'isCharger')){
+                //                 // 重定向到开始路径
+                //                 this.$router.replace('/dashboard')
+                //             } else {
+                //                 this.$router.replace('/')
+                //             }
+                //         }
+
+                //         // 延迟10秒关闭遮盖层
+                //         setTimeout(() => {
+                //             this.loading = false
+                //             loading.close()
+                //         }, 1000)
+                //     }).catch((err) => {
+                //         // 验证码错误自动清空&密码输入错误3次后触发验证码填写模块
+                //         if (err && err.state === 6020104) {
+                //             this.loginForm.captcha = ''
+                //             this.enabledValidCode = true
+                //             this.refreshCode()
+                //         }
+                //         // 有错误状态开启验证码需要刷新验证码
+                //         if (err && err.state && this.enabledValidCode) {
+                //             this.loginForm.captcha = ''
+                //             this.refreshCode()
+                //         }
+                //         this.loading = false
+                //         loading.close()
+                //     })
+                // } else {
+                //     this.$message.closeAll()
+                //     this.$message({
+                //         message: this.$t('common.dialog.saveError'),
+                //         type: 'warning'
+                //     })
+                //     return false
+                // }
+            })
+        },
+        // ca认证
+        caAuth () {
+            SZG_getServerCertificate().then(res1 => {
+                const data1 = res1.variables && res1.variables.data
+                console.log(data1)
+                SZG_genRandom().then(res2 => {
+                    const data2 = res2.variables && res2.variables.data
+                    console.log(data2)
+                    if (data2) {
+                        SZG_signData({ inData: data2 }).then(res3 => {
+                            const data3 = res3.variables && res3.variables.data
+                            console.log(res3, data3)
                         })
-                        return false
                     }
                 })
-            },
-            // ca认证
-            caAuth () {
-                SZG_getServerCertificate().then(res1 => {
-                    let data1 = res1.variables && res1.variables.data
-                    console.log(data1)
-                    SZG_genRandom().then(res2 => {
-                        let data2 = res2.variables && res2.variables.data
-                        console.log(data2)
-                        if (data2) {
-                            SZG_signData({ inData: data2 }).then(res3 => {
-                                let data3 = res3.variables && res3.variables.data
-                                console.log(res3, data3)
-                            })
-                        }
-                    })
-                }).catch(err => {
-                    console.log('获取服务器证书失败!')
-                })
-                // 获取用户列表,并截取用户姓名显示到登录框中
-                this.loginForm.username = xtxsync.SOF_GetUserList()
-            },
-            // 验签
-            caVerify () {
-                xtxsync.SOF_VerifySignedData()
-            }
+            }).catch(err => {
+                console.log('获取服务器证书失败!')
+            })
+            // 获取用户列表,并截取用户姓名显示到登录框中
+            this.loginForm.username = xtxsync.SOF_GetUserList()
+        },
+        // 验签
+        caVerify () {
+            xtxsync.SOF_VerifySignedData()
         }
     }
+}
 </script>
 
 <style scoped>