diff --git a/pages/createKey/createKey.vue b/pages/createKey/createKey.vue index 8df68b7..909fcac 100644 --- a/pages/createKey/createKey.vue +++ b/pages/createKey/createKey.vue @@ -5,7 +5,7 @@ :list="tabs" lineWidth="40rpx" lineHeight="5rpx" - :current="currnetIndex" + :current="current" lineColor="#63b8af" @click="clickTab" :inactiveStyle="{ color: '#a3a3a3', fontSize: '32rpx', fontWeight: 'bold' }" @@ -19,7 +19,7 @@ :list="tabs" :autoplay="false" :circular="true" - :current="currnetIndex" + :current="current" @change="changeSwiper" > @@ -27,13 +27,13 @@ :value="permanentAccount" title="接收者" placeholder="请输入手机号或邮箱" - @change-input="changePermanentAccountInput" + @change-input="changeAccount('permanent', $event)" > 接收者可使用此小程序开关锁 发送 - + 发送 + + + + 单次钥匙有效期为1小时,只能使用一次 + 发送 + + + + + + + + 接收者可以在有效期内的固定时间段里,不限次数使用 + 发送 + @@ -103,17 +138,30 @@ }, { name: '限时' + }, + { + name: '单次' + }, + { + name: '循环' } ], permanentName: '', permanentAccount: '', temporaryName: '', temporaryAccount: '', - temporaryValidTime: Number(new Date()), - temporaryInvalidTime: Number(new Date()), + startDate: Number(new Date()), + endDate: Number(new Date()), + singleName: '', + singleAccount: '', + cycleName: '', + cycleAccount: '', + cycleStartTime: null, + cycleEndTime: null, + weekDays: [], minDate: Number(new Date()), maxDate: Number(4133951940000), - currnetIndex: 0, + current: 0, deviceInfo: null, pending: false } @@ -124,24 +172,24 @@ }, async onLoad() { this.deviceInfo = await this.getDeviceInfo() - // this.temporaryInvalidTime = this.setTime() }, methods: { ...mapActions(useBasicStore, ['getDeviceInfo', 'backAndToast', 'getNetworkType']), ...mapActions(useLockStore, ['getKeyList', 'updateKeySearch']), - setTime() { - const now = new Date() - now.setMinutes(0, 0, 0) - now.setDate(now.getDate() + 3) - - return now.getTime() + changeCycle(data) { + this.cycleStartTime = data.startDate + this.cycleEndTime = data.endDate + this.weekDays = data.weekDays }, async createKey(type, createUser = false) { if ( (type === 'temporary' && !(test.email(this.temporaryAccount) || test.mobile(this.temporaryAccount))) || (type === 'permanent' && - !(test.email(this.permanentAccount) || test.mobile(this.permanentAccount))) + !(test.email(this.permanentAccount) || test.mobile(this.permanentAccount))) || + (type === 'single' && + !(test.email(this.singleAccount) || test.mobile(this.singleAccount))) || + (type === 'cycle' && !(test.email(this.cycleAccount) || test.mobile(this.cycleAccount))) ) { uni.showToast({ title: '请输入格式正确的手机号或邮箱', @@ -150,7 +198,7 @@ return } - if (type === 'temporary' && this.temporaryValidTime >= this.temporaryInvalidTime) { + if (type === 'temporary' && this.startDate >= this.endDate) { uni.showToast({ title: '失效时间必须大于生效时间', icon: 'none' @@ -158,6 +206,14 @@ return } + if (type === 'cycle' && this.weekDays.length === 0) { + uni.showToast({ + title: '请选择有效期', + icon: 'none' + }) + return + } + const netWork = await this.getNetworkType() if (!netWork) { return @@ -183,16 +239,31 @@ } if (type === 'temporary') { params.keyNameForAdmin = this.temporaryName - params.endDate = this.temporaryInvalidTime.toString() + params.endDate = this.endDate.toString() params.keyType = '2' params.receiverUsername = this.temporaryAccount - params.startDate = this.temporaryValidTime.toString() - } else { + params.startDate = this.startDate.toString() + } else if (type === 'permanent') { params.keyNameForAdmin = this.permanentName params.startDate = new Date().getTime().toString() params.endDate = '0' params.keyType = '1' params.receiverUsername = this.permanentAccount + } else if (type === 'single') { + params.keyNameForAdmin = this.singleName + params.startDate = new Date().getTime().toString() + params.endDate = '0' + params.keyType = '3' + params.receiverUsername = this.singleAccount + } else if (type === 'cycle') { + params.keyNameForAdmin = this.cycleName + params.startDate = this.cycleStartTime + params.endDate = this.cycleEndTime + params.keyType = '4' + params.receiverUsername = this.cycleAccount + params.weekDays = this.weekDays + params.startTime = this.cycleStartTime + params.endTime = this.cycleEndTime } const { code, message } = await createKeyRequest(params) if (code === 0) { @@ -222,29 +293,39 @@ } this.pending = false }, - changePermanentAccountInput(e) { - this.permanentAccount = e + changeAccount(type, e) { + if (type === 'permanent') { + this.permanentAccount = e + } else if (type === 'temporary') { + this.temporaryAccount = e + } else if (type === 'single') { + this.singleAccount = e + } else if (type === 'cycle') { + this.cycleAccount = e + } }, - changePermanentNameInput(e) { - this.permanentName = e - }, - changeTemporaryNameInput(e) { - this.temporaryName = e - }, - changeTemporaryAccountInput(e) { - this.temporaryAccount = e + changeName(type, e) { + if (type === 'permanent') { + this.permanentName = e + } else if (type === 'temporary') { + this.temporaryName = e + } else if (type === 'single') { + this.singleName = e + } else if (type === 'cycle') { + this.cycleName = e + } }, changeTemporaryValidTime(e) { - this.temporaryValidTime = e + this.startDate = e }, changeTemporaryInvalidTime(e) { - this.temporaryInvalidTime = e + this.endDate = e }, clickTab(data) { - this.currnetIndex = data.index + this.current = data.index }, changeSwiper(e) { - this.currnetIndex = e.detail.current + this.current = e.detail.current } } }