Files
yunzerwebsiteallinone/uniapp/pages/tools/account/index.vue
T
2026-11-03 09:00:29 +08:00

389 lines
8.2 KiB
Vue

<template>
<view class="page">
<!-- 顶部工具栏 -->
<view class="toolbar">
<u-search
v-model="keyword"
placeholder="搜索平台、网址、账号、备注"
:show-action="false"
bg-color="#eef2f7"
shape="round"
@input="onKeywordInput"
/>
</view>
<!-- 统计 -->
<view class="stats-row">
<text class="stats-text">共 {{ total }} 条</text>
</view>
<!-- 加载中 -->
<view v-if="loading" class="loading-wrap">
<u-loading-icon mode="circle" size="36" color="#2563eb"></u-loading-icon>
</view>
<!-- 空态 -->
<u-empty
v-else-if="!list.length"
mode="data"
text="还没有账号记录"
margin-top="120"
/>
<!-- 账号卡片列表 -->
<view v-else class="store-list">
<view v-for="store in list" :key="store.id" class="store-card">
<!-- 平台头 -->
<view class="store-head" @click="toggleExpand(store.id)">
<view class="store-icon">
<FaIcon name="key" color="#2563eb" :size="18" />
</view>
<view class="store-title-wrap">
<view class="store-title">{{ store.platform || '未命名平台' }}</view>
<view class="store-sub">
<text v-if="store.url">{{ store.url }}</text>
<text v-else class="sub-weak">未填写网址</text>
</view>
</view>
<view class="store-count">
<u-tag
:text="store.accounts.length + ' 个账号'"
plain
size="mini"
type="primary"
/>
</view>
<FaIcon
:name="expandedId === store.id ? 'chevron-up' : 'chevron-down'"
color="#94a3b8"
:size="14"
/>
</view>
<!-- 平台备注 -->
<view v-if="store.remark" class="store-remark">{{ store.remark }}</view>
<!-- 账号明细 -->
<view v-if="expandedId === store.id" class="account-list">
<view v-for="(acc, idx) in store.accounts" :key="idx" class="account-item">
<view class="account-row">
<text class="account-label">账号</text>
<text class="account-value">{{ acc.username || '-' }}</text>
<view class="copy-btn" @click.stop="copyText(acc.username)">
<FaIcon name="copy" color="#2563eb" :size="14" />
</view>
</view>
<view class="account-row">
<text class="account-label">密码</text>
<text class="account-value">{{ shownPwd[accKey(store, idx)] ? (acc.password || '-') : '••••••••' }}</text>
<view class="copy-btn" @click.stop="togglePwd(store, idx)">
<FaIcon :name="shownPwd[accKey(store, idx)] ? 'eye-slash' : 'eye'" color="#94a3b8" :size="14" />
</view>
<view class="copy-btn" @click.stop="copyText(acc.password)">
<FaIcon name="copy" color="#2563eb" :size="14" />
</view>
</view>
<view v-if="acc.registration_info" class="account-row">
<text class="account-label">注册信息</text>
<text class="account-value">{{ acc.registration_info }}</text>
</view>
<view v-if="acc.remark" class="account-row">
<text class="account-label">备注</text>
<text class="account-value">{{ acc.remark }}</text>
</view>
</view>
<view v-if="!store.accounts.length" class="account-empty">该平台暂无账号</view>
</view>
<!-- 操作行 -->
<view class="actions-row">
<view class="action-btn" @click.stop="goEdit(store.id)">
<FaIcon name="pen-to-square" color="#2563eb" :size="14" />
<text class="action-text">编辑</text>
</view>
<view class="action-btn" @click.stop="onDelete(store)">
<FaIcon name="trash-can" color="#ef4444" :size="14" />
<text class="action-text danger">删除</text>
</view>
</view>
</view>
</view>
<!-- 悬浮新增 -->
<view class="fab" @click="goEdit()">
<FaIcon name="plus" color="#ffffff" :size="24" />
</view>
</view>
</template>
<script setup>
import { ref } from 'vue'
import { onLoad, onShow } from '@dcloudio/uni-app'
import { fetchPasswordStores, deletePasswordStore } from '@/api/passwordStore.js'
const keyword = ref('')
const list = ref([])
const loading = ref(true)
const expandedId = ref(0)
const shownPwd = ref({})
const total = ref(0)
const inited = ref(false)
let debounceTimer = 0
function onKeywordInput() {
clearTimeout(debounceTimer)
debounceTimer = setTimeout(loadList, 300)
}
async function loadList() {
loading.value = true
try {
const data = await fetchPasswordStores(keyword.value.trim())
list.value = data.list
total.value = data.total
} finally {
loading.value = false
}
}
function toggleExpand(id) {
expandedId.value = expandedId.value === id ? 0 : id
}
function accKey(store, idx) {
return `${store.id}_${idx}`
}
function togglePwd(store, idx) {
const key = accKey(store, idx)
shownPwd.value = { ...shownPwd.value, [key]: !shownPwd.value[key] }
}
function copyText(text) {
if (!text) {
uni.showToast({ title: '内容为空', icon: 'none' })
return
}
uni.setClipboardData({
data: text,
success: () => uni.showToast({ title: '已复制', icon: 'none' })
})
}
function goEdit(id) {
uni.navigateTo({
url: id ? `/pages/tools/account/edit?id=${id}` : '/pages/tools/account/edit'
})
}
function onDelete(store) {
uni.showModal({
title: '删除记录',
content: `确定删除「${store.platform || '未命名平台'}」及其全部账号?`,
confirmText: '删除',
confirmColor: '#ef4444',
success: async res => {
if (!res.confirm) return
try {
await deletePasswordStore(store.id)
uni.showToast({ title: '已删除', icon: 'none' })
loadList()
} catch (e) {
// 错误提示由 request 层统一处理
}
}
})
}
onLoad(() => loadList())
onShow(() => {
// 从编辑页返回后刷新(首次进入由 onLoad 加载,避免重复请求)
if (inited.value) loadList()
inited.value = true
})
</script>
<style lang="scss" scoped>
.page {
min-height: 100vh;
padding-bottom: calc(180rpx + env(safe-area-inset-bottom));
background: #f8fafc;
}
.toolbar {
padding: 20rpx 24rpx 8rpx;
}
.stats-row {
padding: 8rpx 32rpx 12rpx;
}
.stats-text {
font-size: 24rpx;
color: #94a3b8;
}
.loading-wrap {
padding: 120rpx 0;
display: flex;
justify-content: center;
}
.store-list {
padding: 0 24rpx;
}
.store-card {
background: #ffffff;
border-radius: 16rpx;
padding: 24rpx;
margin-bottom: 20rpx;
box-shadow: 0 4rpx 16rpx rgba(15, 23, 42, 0.05);
}
.store-head {
display: flex;
align-items: center;
gap: 16rpx;
}
.store-icon {
width: 64rpx;
height: 64rpx;
border-radius: 16rpx;
background: #eff6ff;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}
.store-title-wrap {
flex: 1;
min-width: 0;
}
.store-title {
font-size: 30rpx;
font-weight: 600;
color: #0f172a;
word-break: break-all;
}
.store-sub {
margin-top: 4rpx;
font-size: 24rpx;
color: #475569;
word-break: break-all;
}
.sub-weak {
color: #94a3b8;
}
.store-count {
flex-shrink: 0;
}
.store-remark {
margin-top: 16rpx;
padding: 16rpx;
background: #f8fafc;
border-radius: 10rpx;
font-size: 24rpx;
color: #475569;
word-break: break-all;
}
.account-list {
margin-top: 16rpx;
border-top: 1rpx solid #f1f5f9;
}
.account-item {
padding: 16rpx 0;
border-bottom: 1rpx solid #f1f5f9;
}
.account-item:last-child {
border-bottom: none;
}
.account-row {
display: flex;
align-items: center;
gap: 12rpx;
min-height: 56rpx;
}
.account-label {
width: 120rpx;
flex-shrink: 0;
font-size: 24rpx;
color: #94a3b8;
}
.account-value {
flex: 1;
min-width: 0;
font-size: 26rpx;
color: #0f172a;
word-break: break-all;
}
.copy-btn {
padding: 8rpx 12rpx;
flex-shrink: 0;
}
.account-empty {
padding: 24rpx 0;
text-align: center;
font-size: 24rpx;
color: #94a3b8;
}
.actions-row {
display: flex;
justify-content: flex-end;
gap: 32rpx;
margin-top: 16rpx;
padding-top: 16rpx;
border-top: 1rpx solid #f1f5f9;
}
.action-btn {
display: flex;
align-items: center;
gap: 8rpx;
padding: 8rpx 16rpx;
}
.action-text {
font-size: 24rpx;
color: #2563eb;
}
.action-text.danger {
color: #ef4444;
}
.fab {
position: fixed;
right: 40rpx;
bottom: calc(80rpx + env(safe-area-inset-bottom));
width: 104rpx;
height: 104rpx;
border-radius: 52rpx;
background: #2563eb;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 12rpx 32rpx rgba(37, 99, 235, 0.35);
}
.fab:active {
transform: scale(0.94);
}
</style>