完成创建单次、循环电子钥匙功能

This commit is contained in:
范鹏 2025-02-14 10:00:34 +08:00
parent fee5aa62e3
commit 17e820fc62

View File

@ -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"
>
<swiper-item>
@ -27,13 +27,13 @@
:value="permanentAccount"
title="接收者"
placeholder="请输入手机号或邮箱"
@change-input="changePermanentAccountInput"
@change-input="changeAccount('permanent', $event)"
></LockInput>
<LockInput
:value="permanentName"
title="姓名"
placeholder="请输入姓名"
@change-input="changePermanentNameInput"
@change-input="changeName('permanent', $event)"
></LockInput>
<view class="text" style="margin-top: 40rpx">接收者可使用此小程序开关锁</view>
<view class="text" style="margin-bottom: 50rpx"
@ -41,30 +41,30 @@
>
<view class="button" @click="createKey('permanent')">发送</view>
</swiper-item>
<swiper-item :style="{ height: deviceInfo.windowHeight - 44 + 'px' }">
<swiper-item>
<LockInput
:value="temporaryAccount"
title="接收者"
placeholder="请输入手机号或邮箱"
@change-input="changeTemporaryAccountInput"
@change-input="changeAccount('temporary', $event)"
></LockInput>
<LockInput
:value="temporaryName"
title="姓名"
placeholder="请输入姓名"
@change-input="changeTemporaryNameInput"
@change-input="changeName('temporary', $event)"
></LockInput>
<view style="margin-top: 20rpx">
<LockDatetimePicker
title="生效时间"
:value="temporaryValidTime"
:value="startDate"
:minDate="minDate"
@change-time="changeTemporaryValidTime"
:maxDate="maxDate"
></LockDatetimePicker>
<LockDatetimePicker
title="失效时间"
:value="temporaryInvalidTime"
:value="endDate"
:minDate="minDate"
@change-time="changeTemporaryInvalidTime"
:maxDate="maxDate"
@ -76,6 +76,41 @@
>
<view class="button" @click="createKey('temporary')">发送</view>
</swiper-item>
<swiper-item>
<LockInput
:value="singleAccount"
title="接收者"
placeholder="请输入手机号或邮箱"
@change-input="changeAccount('single', $event)"
></LockInput>
<LockInput
:value="singleName"
title="姓名"
placeholder="请输入姓名"
@change-input="changeName('single', $event)"
></LockInput>
<view class="text mt-5 mb-50rpx">单次钥匙有效期为1小时只能使用一次</view>
<view class="button" @click="createKey('single')">发送</view>
</swiper-item>
<swiper-item>
<LockInput
:value="cycleAccount"
title="接收者"
placeholder="请输入手机号或邮箱"
@change-input="changeAccount('cycle', $event)"
></LockInput>
<LockInput
:value="cycleName"
title="姓名"
placeholder="请输入姓名"
@change-input="changeName('cycle', $event)"
></LockInput>
<view style="margin-top: 20rpx">
<LockCycle @change="changeCycle"></LockCycle>
</view>
<view class="text mt-5 mb-50rpx">接收者可以在有效期内的固定时间段里不限次数使用</view>
<view class="button" @click="createKey('cycle')">发送</view>
</swiper-item>
</swiper>
</view>
</template>
@ -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
}
}
}