feat: 添加登录记录
This commit is contained in:
+210
-5
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<!-- 空登陆页 -->
|
||||
<s-layout navbar="inner" title="登录" navPreset="float">
|
||||
<view class="login">
|
||||
<view class="login" @tap="onPageTap">
|
||||
<view class="login_top_img w100" :style="{ top: -height + 'px' }">
|
||||
<image src="@/static/index/login_bg.png" mode="widthFix" class="w100" />
|
||||
</view>
|
||||
@@ -21,7 +21,7 @@
|
||||
:label="dataObj.formArr[v].title"
|
||||
:name="dataObj.formArr[v].value"
|
||||
>
|
||||
<view class="flex-center border_bottom">
|
||||
<view class="flex-center border_bottom login-input-wrap" @tap.stop>
|
||||
<image class="input-icon" :src="inputIconMap[v]" mode="aspectFit" />
|
||||
<uni-easyinput
|
||||
v-model="formData[dataObj.formArr[v].value]"
|
||||
@@ -29,10 +29,40 @@
|
||||
:type="dataObj.formArr[v].type"
|
||||
:inputBorder="false"
|
||||
:maxlength="dataObj.formArr[v].max"
|
||||
@focus="() => onInputFocus(dataObj.formArr[v].value)"
|
||||
@input="() => onInputInput(dataObj.formArr[v].value)"
|
||||
/>
|
||||
<view v-if="v == 2" class="c_code size28" @click="getCode">{{
|
||||
num > 0 && num < 60 ? num + 's后重新获取' : '获取验证码'
|
||||
}}</view>
|
||||
<view
|
||||
v-if="shouldShowDropdownIcon(dataObj.formArr[v].value)"
|
||||
class="login-suggest-icon"
|
||||
@tap.stop="() => onToggleDropdown(dataObj.formArr[v].value)"
|
||||
>
|
||||
<uni-icons type="bottom" size="18" color="#C6C6C6" />
|
||||
</view>
|
||||
</view>
|
||||
<view
|
||||
v-if="shouldShowSuggestionList(dataObj.formArr[v].value)"
|
||||
class="login-suggest"
|
||||
@tap.stop
|
||||
>
|
||||
<view
|
||||
v-for="item in suggestionListFor(dataObj.formArr[v].value)"
|
||||
:key="item.mobile"
|
||||
class="login-suggest-item"
|
||||
@tap.stop="() => onSelectSuggestion(item)"
|
||||
>
|
||||
<template v-if="dataObj.formArr[v].value === 'password'">
|
||||
<view class="login-suggest-title">{{ formatPasswordPreview(item.password) }}</view>
|
||||
<view class="login-suggest-sub">{{ item.mobile }}</view>
|
||||
</template>
|
||||
<template v-else>
|
||||
<view class="login-suggest-title">{{ item.mobile }}</view>
|
||||
<view class="login-suggest-sub">{{ item.hasPassword ? '已保存密码' : '仅保存账号' }}</view>
|
||||
</template>
|
||||
</view>
|
||||
</view>
|
||||
</uni-forms-item>
|
||||
</view>
|
||||
@@ -79,12 +109,17 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive } from 'vue';
|
||||
import { ref, reactive, computed } from 'vue';
|
||||
import sheep from '@/sheep';
|
||||
import { onLoad } from '@dcloudio/uni-app';
|
||||
import AuthUtil from '@/sheep/api/member/auth';
|
||||
let type = ref(2);
|
||||
let formData = reactive({});
|
||||
let formData = reactive({
|
||||
mobile: '',
|
||||
code: '',
|
||||
password: '',
|
||||
confirmPassword: '',
|
||||
});
|
||||
let num = ref(0);
|
||||
const inputIconMap = {
|
||||
1: '/static/icon/icon1.png',
|
||||
@@ -224,6 +259,128 @@
|
||||
const radioChange = (e) => {
|
||||
radioValue.value = e.detail.value;
|
||||
};
|
||||
|
||||
const LOGIN_HISTORY_KEY = 'login-history';
|
||||
const HISTORY_LIMIT = 20;
|
||||
const loginHistory = ref([]);
|
||||
const dropdownVisibleFor = ref('');
|
||||
const hasAnyHistory = computed(() => {
|
||||
const list = Array.isArray(loginHistory.value) ? loginHistory.value : [];
|
||||
return list.length > 0;
|
||||
});
|
||||
|
||||
const canUseLoginHistory = computed(() => {
|
||||
const arr = dataObj?.con?.[type.value]?.arr;
|
||||
return Array.isArray(arr) && arr.includes(3);
|
||||
});
|
||||
|
||||
const mobileQuery = computed(() => String(formData.mobile || '').trim());
|
||||
const filteredHistory = computed(() => {
|
||||
const query = mobileQuery.value;
|
||||
const list = Array.isArray(loginHistory.value) ? loginHistory.value : [];
|
||||
const normalized = list
|
||||
.filter((item) => item && item.mobile)
|
||||
.map((item) => ({
|
||||
mobile: String(item.mobile),
|
||||
password: item.password ? String(item.password) : '',
|
||||
updatedAt: Number(item.updatedAt || 0),
|
||||
hasPassword: Boolean(item.password),
|
||||
}))
|
||||
.sort((a, b) => b.updatedAt - a.updatedAt);
|
||||
if (!query) return normalized;
|
||||
return normalized.filter((item) => item.mobile.includes(query));
|
||||
});
|
||||
|
||||
const passwordHistory = computed(() => filteredHistory.value.filter((item) => item.hasPassword));
|
||||
|
||||
function loadLoginHistory() {
|
||||
try {
|
||||
const raw = uni.getStorageSync(LOGIN_HISTORY_KEY);
|
||||
const parsed = raw ? JSON.parse(raw) : [];
|
||||
loginHistory.value = Array.isArray(parsed) ? parsed : [];
|
||||
} catch (e) {
|
||||
loginHistory.value = [];
|
||||
}
|
||||
}
|
||||
|
||||
function persistLoginHistory() {
|
||||
try {
|
||||
uni.setStorageSync(LOGIN_HISTORY_KEY, JSON.stringify(loginHistory.value.slice(0, HISTORY_LIMIT)));
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
function upsertLoginHistory({ mobile, password }) {
|
||||
const nextMobile = String(mobile || '').trim();
|
||||
if (!/^1\d{10}$/.test(nextMobile)) return;
|
||||
const nextPassword = String(password || '');
|
||||
const now = Date.now();
|
||||
const next = Array.isArray(loginHistory.value) ? [...loginHistory.value] : [];
|
||||
const existingIndex = next.findIndex((item) => String(item?.mobile || '') === nextMobile);
|
||||
const payload = { mobile: nextMobile, password: nextPassword, updatedAt: now };
|
||||
if (existingIndex >= 0) next.splice(existingIndex, 1, payload);
|
||||
else next.unshift(payload);
|
||||
loginHistory.value = next.sort((a, b) => Number(b.updatedAt || 0) - Number(a.updatedAt || 0));
|
||||
persistLoginHistory();
|
||||
}
|
||||
|
||||
function onPageTap() {
|
||||
dropdownVisibleFor.value = '';
|
||||
}
|
||||
|
||||
function onToggleDropdown(field) {
|
||||
if (!canUseLoginHistory.value) return;
|
||||
const next = dropdownVisibleFor.value === field ? '' : field;
|
||||
if (next && !suggestionListFor(field).length) return;
|
||||
dropdownVisibleFor.value = next;
|
||||
}
|
||||
|
||||
function onInputFocus(field) {
|
||||
if (!canUseLoginHistory.value) return;
|
||||
if (field !== 'mobile' && field !== 'password') return;
|
||||
if (!suggestionListFor(field).length) return;
|
||||
dropdownVisibleFor.value = field;
|
||||
}
|
||||
|
||||
function onInputInput(field) {
|
||||
if (!canUseLoginHistory.value) return;
|
||||
if (field !== 'mobile') return;
|
||||
if (!filteredHistory.value.length) {
|
||||
dropdownVisibleFor.value = '';
|
||||
return;
|
||||
}
|
||||
if (dropdownVisibleFor.value !== 'mobile') dropdownVisibleFor.value = 'mobile';
|
||||
}
|
||||
|
||||
function shouldShowDropdownIcon(field) {
|
||||
if (!canUseLoginHistory.value) return false;
|
||||
if (!hasAnyHistory.value) return false;
|
||||
return field === 'mobile' || field === 'password';
|
||||
}
|
||||
|
||||
function shouldShowSuggestionList(field) {
|
||||
if (!canUseLoginHistory.value) return false;
|
||||
if (dropdownVisibleFor.value !== field) return false;
|
||||
return suggestionListFor(field).length > 0;
|
||||
}
|
||||
|
||||
function suggestionListFor(field) {
|
||||
if (field === 'password') return passwordHistory.value;
|
||||
return filteredHistory.value;
|
||||
}
|
||||
|
||||
function onSelectSuggestion(item) {
|
||||
formData.mobile = item.mobile;
|
||||
if (item.hasPassword) formData.password = item.password;
|
||||
dropdownVisibleFor.value = '';
|
||||
}
|
||||
|
||||
function formatPasswordPreview(value) {
|
||||
const text = String(value || '');
|
||||
if (!text) return '******';
|
||||
const len = Math.min(Math.max(text.length, 6), 12);
|
||||
return '•'.repeat(len);
|
||||
}
|
||||
|
||||
const sub = async () => {
|
||||
if (!radioValue.value) {
|
||||
uni.showToast({
|
||||
@@ -272,6 +429,9 @@
|
||||
typeChange(2);
|
||||
return;
|
||||
}
|
||||
if (type.value === 2) {
|
||||
upsertLoginHistory({ mobile: formData.mobile, password: formData.password });
|
||||
}
|
||||
sheep.$store('user').getInfo();
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({ url: '/pages/index/index' });
|
||||
@@ -335,7 +495,9 @@
|
||||
const go = (type) => {
|
||||
uni.navigateTo({ url: '/pages/home/agreement?type=' + type });
|
||||
};
|
||||
onLoad(async () => {});
|
||||
onLoad(async () => {
|
||||
loadLoginHistory();
|
||||
});
|
||||
let sysInfo = uni.getSystemInfoSync();
|
||||
const windowHeight = sysInfo.windowHeight;
|
||||
let height = ref(0);
|
||||
@@ -441,4 +603,47 @@
|
||||
border: none !important;
|
||||
background: transparent !important;
|
||||
}
|
||||
|
||||
.login-input-wrap {
|
||||
position: relative;
|
||||
}
|
||||
.login-suggest-icon {
|
||||
padding-left: 12rpx;
|
||||
padding-right: 6rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
.login-suggest {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
right: 0;
|
||||
top: calc(100% + 8rpx);
|
||||
background: #ffffff;
|
||||
border-radius: 20rpx;
|
||||
box-shadow: 0 16rpx 40rpx rgba(0, 0, 0, 0.12);
|
||||
z-index: 20;
|
||||
overflow: hidden;
|
||||
max-height: 420rpx;
|
||||
}
|
||||
.login-suggest-item {
|
||||
padding: 20rpx 24rpx;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
border-bottom: 2rpx solid rgba(0, 0, 0, 0.06);
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.login-suggest-item:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
.login-suggest-title {
|
||||
font-size: 28rpx;
|
||||
font-weight: 700;
|
||||
color: #111111;
|
||||
}
|
||||
.login-suggest-sub {
|
||||
font-size: 22rpx;
|
||||
color: #9aa0aa;
|
||||
font-weight: 600;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user