2024-08-26 20:04:22 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<view>
|
2024-08-28 16:55:11 +08:00
|
|
|
|
<view class="tabs">
|
2025-02-06 11:37:41 +08:00
|
|
|
|
<up-tabs
|
|
|
|
|
|
:list="tabs"
|
|
|
|
|
|
lineWidth="40rpx"
|
|
|
|
|
|
lineHeight="5rpx"
|
2025-02-14 10:00:34 +08:00
|
|
|
|
:current="current"
|
2025-02-06 11:37:41 +08:00
|
|
|
|
lineColor="#63b8af"
|
|
|
|
|
|
@click="clickTab"
|
|
|
|
|
|
:inactiveStyle="{ color: '#a3a3a3', fontSize: '32rpx', fontWeight: 'bold' }"
|
|
|
|
|
|
:activeStyle="{ color: '#63b8af', fontSize: '32rpx', fontWeight: 'bold' }"
|
|
|
|
|
|
>
|
2024-08-28 16:55:11 +08:00
|
|
|
|
</up-tabs>
|
|
|
|
|
|
</view>
|
2025-02-06 11:37:41 +08:00
|
|
|
|
<swiper
|
|
|
|
|
|
:style="{ height: deviceInfo.screenHeight - deviceInfo.safeArea.top - 44 + 'px' }"
|
|
|
|
|
|
v-if="deviceInfo"
|
|
|
|
|
|
:list="tabs"
|
|
|
|
|
|
:autoplay="false"
|
|
|
|
|
|
:circular="true"
|
2025-02-14 10:00:34 +08:00
|
|
|
|
:current="current"
|
2025-02-06 11:37:41 +08:00
|
|
|
|
@change="changeSwiper"
|
|
|
|
|
|
>
|
2024-08-28 16:55:11 +08:00
|
|
|
|
<swiper-item>
|
2025-02-06 11:37:41 +08:00
|
|
|
|
<LockInput
|
|
|
|
|
|
:value="permanentAccount"
|
|
|
|
|
|
title="接收者"
|
|
|
|
|
|
placeholder="请输入手机号或邮箱"
|
2025-02-14 10:00:34 +08:00
|
|
|
|
@change-input="changeAccount('permanent', $event)"
|
2025-02-06 11:37:41 +08:00
|
|
|
|
></LockInput>
|
|
|
|
|
|
<LockInput
|
|
|
|
|
|
:value="permanentName"
|
|
|
|
|
|
title="姓名"
|
|
|
|
|
|
placeholder="请输入姓名"
|
2025-02-14 10:00:34 +08:00
|
|
|
|
@change-input="changeName('permanent', $event)"
|
2025-02-06 11:37:41 +08:00
|
|
|
|
></LockInput>
|
|
|
|
|
|
<view class="text" style="margin-top: 40rpx">接收者可使用此小程序开关锁</view>
|
|
|
|
|
|
<view class="text" style="margin-bottom: 50rpx"
|
|
|
|
|
|
>小程序暂不支持邮箱登录,若接收者账号为邮箱可先使用星星锁APP登录,绑定手机号后可使用小程序登录</view
|
|
|
|
|
|
>
|
2024-09-26 17:40:44 +08:00
|
|
|
|
<view class="button" @click="createKey('permanent')">发送</view>
|
2024-08-28 16:55:11 +08:00
|
|
|
|
</swiper-item>
|
2025-02-14 10:00:34 +08:00
|
|
|
|
<swiper-item>
|
2025-02-06 11:37:41 +08:00
|
|
|
|
<LockInput
|
|
|
|
|
|
:value="temporaryAccount"
|
|
|
|
|
|
title="接收者"
|
|
|
|
|
|
placeholder="请输入手机号或邮箱"
|
2025-02-14 10:00:34 +08:00
|
|
|
|
@change-input="changeAccount('temporary', $event)"
|
2025-02-06 11:37:41 +08:00
|
|
|
|
></LockInput>
|
|
|
|
|
|
<LockInput
|
|
|
|
|
|
:value="temporaryName"
|
|
|
|
|
|
title="姓名"
|
|
|
|
|
|
placeholder="请输入姓名"
|
2025-02-14 10:00:34 +08:00
|
|
|
|
@change-input="changeName('temporary', $event)"
|
2025-02-06 11:37:41 +08:00
|
|
|
|
></LockInput>
|
2024-08-28 16:55:11 +08:00
|
|
|
|
<view style="margin-top: 20rpx">
|
2025-02-06 11:37:41 +08:00
|
|
|
|
<LockDatetimePicker
|
|
|
|
|
|
title="生效时间"
|
2025-02-14 10:00:34 +08:00
|
|
|
|
:value="startDate"
|
2025-02-06 11:37:41 +08:00
|
|
|
|
:minDate="minDate"
|
|
|
|
|
|
@change-time="changeTemporaryValidTime"
|
|
|
|
|
|
:maxDate="maxDate"
|
|
|
|
|
|
></LockDatetimePicker>
|
|
|
|
|
|
<LockDatetimePicker
|
|
|
|
|
|
title="失效时间"
|
2025-02-14 10:00:34 +08:00
|
|
|
|
:value="endDate"
|
2025-02-06 11:37:41 +08:00
|
|
|
|
:minDate="minDate"
|
|
|
|
|
|
@change-time="changeTemporaryInvalidTime"
|
|
|
|
|
|
:maxDate="maxDate"
|
|
|
|
|
|
></LockDatetimePicker>
|
2024-08-28 16:55:11 +08:00
|
|
|
|
</view>
|
2025-02-06 11:37:41 +08:00
|
|
|
|
<view class="text" style="margin-top: 40rpx">接收者在有效期内可以不限次数使用</view>
|
|
|
|
|
|
<view class="text" style="margin-bottom: 50rpx"
|
|
|
|
|
|
>小程序暂不支持邮箱登录,若接收者账号为邮箱可先使用星星锁APP登录,绑定手机号后可使用小程序登录</view
|
|
|
|
|
|
>
|
2024-09-26 17:40:44 +08:00
|
|
|
|
<view class="button" @click="createKey('temporary')">发送</view>
|
2024-08-28 16:55:11 +08:00
|
|
|
|
</swiper-item>
|
2025-02-14 10:00:34 +08:00
|
|
|
|
<swiper-item>
|
|
|
|
|
|
<LockInput
|
|
|
|
|
|
:value="singleAccount"
|
|
|
|
|
|
title="接收者"
|
|
|
|
|
|
placeholder="请输入手机号或邮箱"
|
|
|
|
|
|
@change-input="changeAccount('single', $event)"
|
|
|
|
|
|
></LockInput>
|
|
|
|
|
|
<LockInput
|
|
|
|
|
|
:value="singleName"
|
|
|
|
|
|
title="姓名"
|
|
|
|
|
|
placeholder="请输入姓名"
|
|
|
|
|
|
@change-input="changeName('single', $event)"
|
|
|
|
|
|
></LockInput>
|
2025-02-21 10:08:06 +08:00
|
|
|
|
<view class="text mt-5">单次钥匙有效期为1小时,只能使用一次</view>
|
|
|
|
|
|
<view class="text" style="margin-bottom: 50rpx">
|
|
|
|
|
|
小程序暂不支持邮箱登录,若接收者账号为邮箱可先使用星星锁APP登录,绑定手机号后可使用小程序登录
|
|
|
|
|
|
</view>
|
2025-02-14 10:00:34 +08:00
|
|
|
|
<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>
|
2025-02-21 10:08:06 +08:00
|
|
|
|
<view class="text mt-5">接收者可以在有效期内的固定时间段里,不限次数使用</view>
|
|
|
|
|
|
<view class="text" style="margin-bottom: 50rpx"
|
|
|
|
|
|
>小程序暂不支持邮箱登录,若接收者账号为邮箱可先使用星星锁APP登录,绑定手机号后可使用小程序登录</view
|
|
|
|
|
|
>
|
2025-02-14 10:00:34 +08:00
|
|
|
|
<view class="button" @click="createKey('cycle')">发送</view>
|
|
|
|
|
|
</swiper-item>
|
2024-08-28 16:55:11 +08:00
|
|
|
|
</swiper>
|
2024-08-26 20:04:22 +08:00
|
|
|
|
</view>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
2025-02-06 11:37:41 +08:00
|
|
|
|
import { mapActions, mapState } from 'pinia'
|
|
|
|
|
|
import { test } from 'uview-plus'
|
|
|
|
|
|
import { useBasicStore } from '@/stores/basic'
|
|
|
|
|
|
import LockInput from '@/components/LockInput/LockInput.vue'
|
|
|
|
|
|
import LockDatetimePicker from '@/components/LockDatetimePicker/LockDatetimePicker.vue'
|
|
|
|
|
|
import { useBluetoothStore } from '@/stores/bluetooth'
|
|
|
|
|
|
import { useLockStore } from '@/stores/lock'
|
|
|
|
|
|
import { createKeyRequest } from '@/api/key'
|
2024-08-28 16:55:11 +08:00
|
|
|
|
|
2025-02-06 11:37:41 +08:00
|
|
|
|
export default {
|
|
|
|
|
|
components: {
|
|
|
|
|
|
LockInput,
|
|
|
|
|
|
LockDatetimePicker
|
2024-08-28 16:55:11 +08:00
|
|
|
|
},
|
2025-02-06 11:37:41 +08:00
|
|
|
|
data() {
|
|
|
|
|
|
return {
|
|
|
|
|
|
tabs: [
|
|
|
|
|
|
{
|
|
|
|
|
|
name: '永久'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
name: '限时'
|
2025-02-14 10:00:34 +08:00
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
name: '单次'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
name: '循环'
|
2025-02-06 11:37:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
],
|
|
|
|
|
|
permanentName: '',
|
|
|
|
|
|
permanentAccount: '',
|
|
|
|
|
|
temporaryName: '',
|
|
|
|
|
|
temporaryAccount: '',
|
2025-02-14 10:00:34 +08:00
|
|
|
|
startDate: Number(new Date()),
|
|
|
|
|
|
endDate: Number(new Date()),
|
|
|
|
|
|
singleName: '',
|
|
|
|
|
|
singleAccount: '',
|
|
|
|
|
|
cycleName: '',
|
|
|
|
|
|
cycleAccount: '',
|
|
|
|
|
|
cycleStartTime: null,
|
|
|
|
|
|
cycleEndTime: null,
|
|
|
|
|
|
weekDays: [],
|
2025-02-06 11:37:41 +08:00
|
|
|
|
minDate: Number(new Date()),
|
|
|
|
|
|
maxDate: Number(4133951940000),
|
2025-02-14 10:00:34 +08:00
|
|
|
|
current: 0,
|
2025-02-06 11:37:41 +08:00
|
|
|
|
deviceInfo: null,
|
|
|
|
|
|
pending: false
|
2024-08-28 16:55:11 +08:00
|
|
|
|
}
|
2025-02-06 11:37:41 +08:00
|
|
|
|
},
|
|
|
|
|
|
computed: {
|
|
|
|
|
|
...mapState(useBluetoothStore, ['currentLockInfo']),
|
|
|
|
|
|
...mapState(useLockStore, ['keySearch'])
|
|
|
|
|
|
},
|
|
|
|
|
|
async onLoad() {
|
|
|
|
|
|
this.deviceInfo = await this.getDeviceInfo()
|
|
|
|
|
|
},
|
|
|
|
|
|
methods: {
|
|
|
|
|
|
...mapActions(useBasicStore, ['getDeviceInfo', 'backAndToast', 'getNetworkType']),
|
|
|
|
|
|
...mapActions(useLockStore, ['getKeyList', 'updateKeySearch']),
|
2025-02-14 10:00:34 +08:00
|
|
|
|
changeCycle(data) {
|
|
|
|
|
|
this.cycleStartTime = data.startDate
|
|
|
|
|
|
this.cycleEndTime = data.endDate
|
|
|
|
|
|
this.weekDays = data.weekDays
|
2025-02-06 11:37:41 +08:00
|
|
|
|
},
|
|
|
|
|
|
async createKey(type, createUser = false) {
|
|
|
|
|
|
if (
|
|
|
|
|
|
(type === 'temporary' &&
|
|
|
|
|
|
!(test.email(this.temporaryAccount) || test.mobile(this.temporaryAccount))) ||
|
|
|
|
|
|
(type === 'permanent' &&
|
2025-02-14 10:00:34 +08:00
|
|
|
|
!(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)))
|
2025-02-06 11:37:41 +08:00
|
|
|
|
) {
|
|
|
|
|
|
uni.showToast({
|
|
|
|
|
|
title: '请输入格式正确的手机号或邮箱',
|
|
|
|
|
|
icon: 'none'
|
|
|
|
|
|
})
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
2024-08-28 16:55:11 +08:00
|
|
|
|
|
2025-02-14 10:00:34 +08:00
|
|
|
|
if (type === 'temporary' && this.startDate >= this.endDate) {
|
2025-02-06 11:37:41 +08:00
|
|
|
|
uni.showToast({
|
|
|
|
|
|
title: '失效时间必须大于生效时间',
|
|
|
|
|
|
icon: 'none'
|
|
|
|
|
|
})
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
2024-09-07 13:34:37 +08:00
|
|
|
|
|
2025-02-14 10:00:34 +08:00
|
|
|
|
if (type === 'cycle' && this.weekDays.length === 0) {
|
|
|
|
|
|
uni.showToast({
|
|
|
|
|
|
title: '请选择有效期',
|
|
|
|
|
|
icon: 'none'
|
|
|
|
|
|
})
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-06 11:37:41 +08:00
|
|
|
|
const netWork = await this.getNetworkType()
|
|
|
|
|
|
if (!netWork) {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
2024-08-28 16:55:11 +08:00
|
|
|
|
|
2025-02-06 11:37:41 +08:00
|
|
|
|
if (this.pending) {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
this.pending = true
|
|
|
|
|
|
|
|
|
|
|
|
let params = {
|
|
|
|
|
|
faceAuthentication: '2',
|
|
|
|
|
|
isRemoteUnlock: '2',
|
|
|
|
|
|
lockId: this.currentLockInfo.lockId,
|
|
|
|
|
|
keyRight: '0',
|
|
|
|
|
|
remarks: '',
|
|
|
|
|
|
countryCode: '86',
|
|
|
|
|
|
createUser: '0'
|
|
|
|
|
|
}
|
|
|
|
|
|
if (createUser) {
|
|
|
|
|
|
params.createUser = '1'
|
|
|
|
|
|
params.usernameType = test.mobile(this.temporaryAccount) ? '1' : '2'
|
|
|
|
|
|
}
|
|
|
|
|
|
if (type === 'temporary') {
|
|
|
|
|
|
params.keyNameForAdmin = this.temporaryName
|
2025-02-14 10:00:34 +08:00
|
|
|
|
params.endDate = this.endDate.toString()
|
2025-02-06 11:37:41 +08:00
|
|
|
|
params.keyType = '2'
|
|
|
|
|
|
params.receiverUsername = this.temporaryAccount
|
2025-02-14 10:00:34 +08:00
|
|
|
|
params.startDate = this.startDate.toString()
|
|
|
|
|
|
} else if (type === 'permanent') {
|
2025-02-06 11:37:41 +08:00
|
|
|
|
params.keyNameForAdmin = this.permanentName
|
|
|
|
|
|
params.startDate = new Date().getTime().toString()
|
|
|
|
|
|
params.endDate = '0'
|
|
|
|
|
|
params.keyType = '1'
|
|
|
|
|
|
params.receiverUsername = this.permanentAccount
|
2025-02-14 10:00:34 +08:00
|
|
|
|
} 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
|
2025-02-06 11:37:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
const { code, message } = await createKeyRequest(params)
|
|
|
|
|
|
if (code === 0) {
|
|
|
|
|
|
uni.reportEvent('create_key', {})
|
|
|
|
|
|
this.updateKeySearch({
|
|
|
|
|
|
...this.keySearch,
|
|
|
|
|
|
pageNo: 1
|
|
|
|
|
|
})
|
|
|
|
|
|
this.getKeyList(this.keySearch)
|
|
|
|
|
|
this.backAndToast('钥匙已发送')
|
|
|
|
|
|
} else if (code === 425) {
|
|
|
|
|
|
this.pending = false
|
|
|
|
|
|
uni.showModal({
|
|
|
|
|
|
title: '提示',
|
|
|
|
|
|
content: `是否发送电子钥匙给未注册账号\n${params.receiverUsername}`,
|
|
|
|
|
|
success: async res => {
|
|
|
|
|
|
if (res.confirm) {
|
|
|
|
|
|
await this.createKey(type, true)
|
|
|
|
|
|
}
|
2024-09-02 09:38:27 +08:00
|
|
|
|
}
|
2025-02-06 11:37:41 +08:00
|
|
|
|
})
|
|
|
|
|
|
} else {
|
|
|
|
|
|
uni.showToast({
|
|
|
|
|
|
title: message,
|
|
|
|
|
|
icon: 'none'
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
this.pending = false
|
|
|
|
|
|
},
|
2025-02-14 10:00:34 +08:00
|
|
|
|
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
|
|
|
|
|
|
}
|
2025-02-06 11:37:41 +08:00
|
|
|
|
},
|
2025-02-14 10:00:34 +08:00
|
|
|
|
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
|
|
|
|
|
|
}
|
2025-02-06 11:37:41 +08:00
|
|
|
|
},
|
|
|
|
|
|
changeTemporaryValidTime(e) {
|
2025-02-14 10:00:34 +08:00
|
|
|
|
this.startDate = e
|
2025-02-06 11:37:41 +08:00
|
|
|
|
},
|
|
|
|
|
|
changeTemporaryInvalidTime(e) {
|
2025-02-14 10:00:34 +08:00
|
|
|
|
this.endDate = e
|
2025-02-06 11:37:41 +08:00
|
|
|
|
},
|
|
|
|
|
|
clickTab(data) {
|
2025-02-14 10:00:34 +08:00
|
|
|
|
this.current = data.index
|
2025-02-06 11:37:41 +08:00
|
|
|
|
},
|
|
|
|
|
|
changeSwiper(e) {
|
2025-02-14 10:00:34 +08:00
|
|
|
|
this.current = e.detail.current
|
2024-08-28 16:55:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-08-26 20:04:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style lang="scss">
|
2025-02-06 11:37:41 +08:00
|
|
|
|
page {
|
|
|
|
|
|
background-color: $uni-bg-color-grey;
|
|
|
|
|
|
}
|
2024-08-28 16:55:11 +08:00
|
|
|
|
</style>
|
|
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2025-02-06 11:37:41 +08:00
|
|
|
|
.tabs {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
}
|
2024-08-28 16:55:11 +08:00
|
|
|
|
|
2025-02-06 11:37:41 +08:00
|
|
|
|
.text {
|
|
|
|
|
|
color: #262626;
|
|
|
|
|
|
font-size: 26rpx;
|
|
|
|
|
|
padding: 0 32rpx;
|
|
|
|
|
|
}
|
2024-08-26 20:04:22 +08:00
|
|
|
|
|
2025-02-06 11:37:41 +08:00
|
|
|
|
.button {
|
|
|
|
|
|
border-radius: 64rpx;
|
|
|
|
|
|
width: 686rpx;
|
|
|
|
|
|
margin-left: 32rpx;
|
|
|
|
|
|
height: 100rpx;
|
|
|
|
|
|
line-height: 100rpx;
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
background-color: #63b8af;
|
|
|
|
|
|
color: #fff;
|
|
|
|
|
|
font-size: 32rpx;
|
|
|
|
|
|
font-weight: bold;
|
|
|
|
|
|
}
|
2024-08-26 20:04:22 +08:00
|
|
|
|
</style>
|