wizhi更新

This commit is contained in:
hero920103 committed 2026-11-03 09:00:29 +08:00
1 parent d4e89788c5
commit 0c6efc4160
16 files changed
+11810 -811

No files matched your search

+399
View File
@@ -0,0 +1,399 @@
<template>
<view class="page">
<!-- 平台信息 -->
<view class="section-card">
<view class="section-title">平台信息</view>
<view class="field">
<text class="field-label">平台名称 <text class="required">*</text></text>
<u-input
v-model="form.platform"
placeholder="如:淘宝、企业微信"
border="surround"
maxlength="50"
/>
</view>
<view class="field">
<text class="field-label">登录网址</text>
<u-input
v-model="form.url"
placeholder="如:https://login.taobao.com"
border="surround"
maxlength="255"
/>
</view>
<view class="field">
<text class="field-label">平台备注</text>
<u-textarea
v-model="form.remark"
placeholder="选填,如:工作用账号"
border="surround"
maxlength="255"
auto-height
/>
</view>
</view>
<!-- 挂载账号列表 -->
<view class="section-card">
<view class="section-head">
<text class="section-title">挂载账号列表</text>
<view class="add-acc-btn" @click="addAccount">
<FaIcon name="plus" color="#2563eb" :size="13" />
<text class="add-acc-text">添加账号</text>
</view>
</view>
<view v-for="(acc, idx) in form.accounts" :key="idx" class="acc-block">
<view class="acc-head">
<text class="acc-index">账号 {{ idx + 1 }}</text>
<view class="acc-del" @click="removeAccount(idx)">
<FaIcon name="trash-can" color="#ef4444" :size="14" />
<text class="acc-del-text">删除</text>
</view>
</view>
<view class="field">
<text class="field-label">账号 / 用户名</text>
<u-input
v-model="acc.username"
placeholder="登录账号或用户名"
border="surround"
maxlength="100"
/>
</view>
<view class="field">
<view class="field-label-row">
<text class="field-label">登录密码</text>
<view class="gen-btn" @click="genPassword(idx)">
<FaIcon name="rotate" color="#2563eb" :size="12" />
<text class="gen-text">随机生成</text>
</view>
</view>
<view class="pwd-row">
<u-input
v-model="acc.password"
:password="!shownPwd[idx]"
placeholder="登录密码"
border="surround"
maxlength="50"
/>
<view class="pwd-eye" @click="shownPwd[idx] = !shownPwd[idx]">
<FaIcon :name="shownPwd[idx] ? 'eye-slash' : 'eye'" color="#94a3b8" :size="16" />
</view>
</view>
</view>
<view class="field">
<text class="field-label">注册信息</text>
<u-textarea
v-model="acc.registration_info"
placeholder="选填,如:注册手机号、邮箱"
border="surround"
maxlength="255"
auto-height
/>
</view>
<view class="field">
<text class="field-label">账号备注</text>
<u-textarea
v-model="acc.remark"
placeholder="选填"
border="surround"
maxlength="255"
auto-height
/>
</view>
</view>
<view v-if="!form.accounts.length" class="acc-empty">
暂无账号,点击右上角「添加账号」
</view>
</view>
<!-- 保存 -->
<view class="footer">
<u-button
type="primary"
text="保存"
:loading="saving"
:disabled="saving"
shape="circle"
@click="onSubmit"
/>
<u-button
v-if="id"
type="error"
plain
text="删除记录"
shape="circle"
@click="onDelete"
/>
</view>
</view>
</template>
<script setup>
import { ref, reactive } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import {
getPasswordStore,
createPasswordStore,
updatePasswordStore,
deletePasswordStore
} from '@/api/passwordStore.js'
const id = ref(0)
const saving = ref(false)
const shownPwd = ref({})
const form = reactive({
platform: '',
url: '',
remark: '',
accounts: []
})
function blankAccount() {
return { username: '', password: '', registration_info: '', remark: '' }
}
function addAccount() {
form.accounts.push(blankAccount())
}
function removeAccount(idx) {
form.accounts.splice(idx, 1)
}
function genPassword(idx) {
const chars = 'ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789!@#$%^&*'
let pwd = ''
for (let i = 0; i < 16; i++) {
pwd += chars.charAt(Math.floor(Math.random() * chars.length))
}
form.accounts[idx].password = pwd
shownPwd.value[idx] = true
uni.showToast({ title: '已生成随机密码', icon: 'none' })
}
async function loadDetail() {
uni.showLoading({ title: '加载中' })
try {
const data = await getPasswordStore(id.value)
form.platform = data.platform
form.url = data.url
form.remark = data.remark
form.accounts = data.accounts.length ? data.accounts : [blankAccount()]
} finally {
uni.hideLoading()
}
}
function validate() {
if (!form.platform.trim()) {
uni.showToast({ title: '请输入平台名称', icon: 'none' })
return false
}
return true
}
async function onSubmit() {
if (!validate()) return
saving.value = true
try {
const payload = {
platform: form.platform.trim(),
url: form.url.trim(),
remark: form.remark.trim(),
accounts: form.accounts.filter(
a => a.username || a.password || a.registration_info || a.remark
)
}
if (id.value) {
await updatePasswordStore(id.value, payload)
} else {
await createPasswordStore(payload)
}
uni.showToast({ title: '保存成功', icon: 'success' })
setTimeout(() => uni.navigateBack(), 400)
} catch (e) {
// 错误提示由 request 层统一处理
} finally {
saving.value = false
}
}
function onDelete() {
uni.showModal({
title: '删除记录',
content: '确定删除该平台及其全部账号?',
confirmText: '删除',
confirmColor: '#ef4444',
success: async res => {
if (!res.confirm) return
try {
await deletePasswordStore(id.value)
uni.showToast({ title: '已删除', icon: 'none' })
setTimeout(() => uni.navigateBack(), 400)
} catch (e) {
// 错误提示由 request 层统一处理
}
}
})
}
onLoad(options => {
if (options.id) {
id.value = Number(options.id)
uni.setNavigationBarTitle({ title: '编辑账号' })
loadDetail()
} else {
form.accounts.push(blankAccount())
}
})
</script>
<style lang="scss" scoped>
.page {
min-height: 100vh;
padding: 24rpx 24rpx calc(60rpx + env(safe-area-inset-bottom));
background: #f8fafc;
}
.section-card {
background: #ffffff;
border-radius: 16rpx;
padding: 24rpx;
margin-bottom: 24rpx;
box-shadow: 0 4rpx 16rpx rgba(15, 23, 42, 0.05);
}
.section-head {
display: flex;
align-items: center;
justify-content: space-between;
}
.section-title {
font-size: 28rpx;
font-weight: 600;
color: #0f172a;
margin-bottom: 8rpx;
}
.add-acc-btn {
display: flex;
align-items: center;
gap: 6rpx;
padding: 10rpx 16rpx;
}
.add-acc-text {
font-size: 24rpx;
color: #2563eb;
}
.field {
margin-top: 24rpx;
}
.field-label {
display: block;
font-size: 26rpx;
color: #475569;
margin-bottom: 12rpx;
}
.required {
color: #ef4444;
}
.field-label-row {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12rpx;
}
.field-label-row .field-label {
margin-bottom: 0;
}
.gen-btn {
display: flex;
align-items: center;
gap: 6rpx;
padding: 6rpx 12rpx;
}
.gen-text {
font-size: 22rpx;
color: #2563eb;
}
.pwd-row {
display: flex;
align-items: center;
gap: 12rpx;
}
.pwd-row :deep(.u-input) {
flex: 1;
min-width: 0;
}
.pwd-eye {
padding: 10rpx;
flex-shrink: 0;
}
.acc-block {
margin-top: 24rpx;
padding: 20rpx;
background: #f8fafc;
border-radius: 16rpx;
}
.acc-head {
display: flex;
align-items: center;
justify-content: space-between;
}
.acc-index {
font-size: 26rpx;
font-weight: 600;
color: #0f172a;
}
.acc-del {
display: flex;
align-items: center;
gap: 6rpx;
padding: 6rpx 12rpx;
}
.acc-del-text {
font-size: 22rpx;
color: #ef4444;
}
.acc-empty {
padding: 32rpx 0;
text-align: center;
font-size: 24rpx;
color: #94a3b8;
}
.footer {
margin-top: 40rpx;
display: flex;
flex-direction: column;
gap: 20rpx;
}
</style>
+388
View File
@@ -0,0 +1,388 @@
<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>
@@ -0,0 +1,377 @@
<template>
<view class="page">
<view class="form-card">
<view class="field">
<text class="field-label">日程内容 <text class="required">*</text></text>
<u-textarea
v-model="form.content"
placeholder="输入日程提醒内容"
:maxlength="500"
count
height="140"
border="none"
/>
</view>
<view class="field">
<text class="field-label">日程时间 <text class="required">*</text></text>
<view class="dt-row">
<picker mode="date" :value="form.date" @change="onDateChange" class="dt-picker">
<view class="picker-value">
<text>{{ form.date || '选择日期' }}</text>
<FaIcon name="calendar-days" color="#94a3b8" :size="15" />
</view>
</picker>
<picker mode="time" :value="form.time" @change="onTimeChange" class="dt-picker">
<view class="picker-value">
<text>{{ form.time || '选择时间' }}</text>
<FaIcon name="clock" color="#94a3b8" :size="15" />
</view>
</picker>
</view>
</view>
<view class="field">
<text class="field-label">提前提醒</text>
<picker :range="minutesLabels" :value="minutesIndex" @change="onMinutesChange">
<view class="picker-value">
<text>{{ minutesLabels[minutesIndex] }}</text>
<FaIcon name="bell" color="#94a3b8" :size="15" />
</view>
</picker>
</view>
<view class="field">
<text class="field-label">提醒渠道 <text class="required">*</text></text>
<view class="channel-grid">
<view
v-for="opt in channelOptions"
:key="opt.value"
class="channel-chip"
:class="{ active: form.remindChannels.includes(opt.value), disabled: opt.disabled }"
@tap="toggleChannel(opt)"
>
<text>{{ opt.label }}</text>
</view>
</view>
<text class="form-tip">可多选,至少选择一个提醒渠道</text>
</view>
<template v-if="hasRepeatChannel">
<view class="field">
<text class="field-label">重复提醒间隔</text>
<picker :range="repeatLabels" :value="repeatIndex" @change="onRepeatChange">
<view class="picker-value">
<text>{{ repeatLabels[repeatIndex] }}</text>
<FaIcon name="rotate" color="#94a3b8" :size="15" />
</view>
</picker>
<text class="form-tip">仅邮件 / Bark 渠道支持重复提醒</text>
</view>
<view v-if="form.repeatIntervalMinutes > 0" class="field">
<text class="field-label">最大发送次数</text>
<picker :range="maxSendLabels" :value="maxSendIndex" @change="onMaxSendChange">
<view class="picker-value">
<text>{{ maxSendLabels[maxSendIndex] }}</text>
<FaIcon name="clock" color="#94a3b8" :size="15" />
</view>
</picker>
</view>
</template>
</view>
<view class="footer">
<u-button
type="primary"
color="#2563eb"
shape="circle"
:loading="saving"
loading-text="保存中..."
text="保存"
@click="onSave"
/>
</view>
</view>
</template>
<script setup>
import { ref, reactive, computed } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import {
getSchedule,
createSchedule,
updateSchedule,
REMIND_CHANNEL_OPTIONS,
REMIND_MINUTES_OPTIONS
} from '@/api/schedule.js'
import { formatDate, pad } from '@/utils/date.js'
const reminderId = ref('')
const saving = ref(false)
// 渠道选择:Bark/APP 暂时隐藏,短信暂不可选
const channelOptions = REMIND_CHANNEL_OPTIONS
.filter(opt => opt.value !== 'bark' && opt.value !== 'app')
.map(opt => ({ ...opt, disabled: opt.value === 'sms' }))
const minutesLabels = REMIND_MINUTES_OPTIONS.map(item => item.label)
const REPEAT_OPTIONS = [
{ label: '不重复', value: 0 },
{ label: '每 10 分钟', value: 10 },
{ label: '每 30 分钟', value: 30 },
{ label: '每 1 小时', value: 60 },
{ label: '每 6 小时', value: 360 },
{ label: '每 1 天', value: 1440 }
]
const repeatLabels = REPEAT_OPTIONS.map(item => item.label)
const MAX_SEND_OPTIONS = [1, 2, 3, 5, 10]
const maxSendLabels = MAX_SEND_OPTIONS.map(n => `${n} 次`)
const form = reactive({
content: '',
date: '',
time: '',
remindMinutes: 15,
remindChannels: ['site'],
repeatIntervalMinutes: 0,
maxSendCount: 1
})
const minutesIndex = computed(() => {
const i = REMIND_MINUTES_OPTIONS.findIndex(item => item.value === form.remindMinutes)
return i >= 0 ? i : 2
})
const repeatIndex = computed(() => {
const i = REPEAT_OPTIONS.findIndex(item => item.value === form.repeatIntervalMinutes)
return i >= 0 ? i : 0
})
const maxSendIndex = computed(() => {
const i = MAX_SEND_OPTIONS.indexOf(form.maxSendCount)
return i >= 0 ? i : 0
})
const hasRepeatChannel = computed(() =>
form.remindChannels.some(ch => ch === 'email' || ch === 'bark')
)
onLoad(async (query) => {
const now = new Date()
form.date = formatDate(now)
form.time = `${pad(now.getHours())}:${pad(now.getMinutes())}`
if (query?.id) {
reminderId.value = query.id
uni.setNavigationBarTitle({ title: '编辑日程提醒' })
await loadReminder(query.id)
} else {
uni.setNavigationBarTitle({ title: '新增日程提醒' })
}
})
async function loadReminder(id) {
try {
const item = await getSchedule(id)
if (!item) {
uni.showToast({ title: '日程不存在', icon: 'none' })
setTimeout(() => uni.navigateBack(), 800)
return
}
form.content = item.content || ''
if (item.datetime) {
const d = new Date(item.datetime)
form.date = formatDate(d)
form.time = `${pad(d.getHours())}:${pad(d.getMinutes())}`
}
form.remindMinutes = item.remindMinutes ?? 15
form.remindChannels = (item.remindChannels || [])
.filter(ch => ch !== 'bark' && ch !== 'app')
form.repeatIntervalMinutes = item.repeatIntervalMinutes ?? 0
form.maxSendCount = item.maxSendCount ?? 1
if (!form.remindChannels.length) form.remindChannels = ['site']
} catch (e) {
uni.showToast({ title: '加载失败', icon: 'none' })
}
}
function onDateChange(e) {
form.date = e.detail.value
}
function onTimeChange(e) {
form.time = e.detail.value
}
function onMinutesChange(e) {
form.remindMinutes = REMIND_MINUTES_OPTIONS[Number(e.detail.value)].value
}
function onRepeatChange(e) {
form.repeatIntervalMinutes = REPEAT_OPTIONS[Number(e.detail.value)].value
}
function onMaxSendChange(e) {
form.maxSendCount = MAX_SEND_OPTIONS[Number(e.detail.value)]
}
function toggleChannel(opt) {
if (opt.disabled) {
uni.showToast({ title: '短信提醒暂不可用', icon: 'none' })
return
}
const i = form.remindChannels.indexOf(opt.value)
if (i >= 0) {
form.remindChannels.splice(i, 1)
} else {
form.remindChannels.push(opt.value)
}
}
async function onSave() {
if (saving.value) return
if (!form.content.trim()) {
uni.showToast({ title: '请输入日程内容', icon: 'none' })
return
}
if (!form.date || !form.time) {
uni.showToast({ title: '请选择日程时间', icon: 'none' })
return
}
if (!form.remindChannels.length) {
uni.showToast({ title: '请选择提醒渠道', icon: 'none' })
return
}
saving.value = true
const [y, m, d] = form.date.split('-').map(Number)
const [hh, mm] = form.time.split(':').map(Number)
const payload = {
content: form.content.trim(),
datetime: new Date(y, m - 1, d, hh, mm).getTime(),
remindChannels: form.remindChannels.slice(),
remindMinutes: form.remindMinutes,
repeatIntervalMinutes: form.repeatIntervalMinutes,
maxSendCount: form.maxSendCount
}
try {
if (reminderId.value) {
await updateSchedule(reminderId.value, payload)
} else {
await createSchedule(payload)
}
uni.showToast({ title: '保存成功', icon: 'success' })
setTimeout(() => uni.navigateBack(), 400)
} catch (e) {
// request 封装已弹出服务端错误提示
} finally {
saving.value = false
}
}
</script>
<style lang="scss" scoped>
@import '@/src/styles/page-common.scss';
.page {
min-height: 100vh;
background: $color-bg-page;
padding: 24rpx $page-padding-x;
padding-bottom: calc(180rpx + env(safe-area-inset-bottom));
}
.form-card {
@include card;
padding: 8rpx 0;
}
.field {
padding: 24rpx 28rpx;
& + & {
border-top: 1rpx solid $color-divider;
}
}
.field-label {
display: block;
font-size: 24rpx;
color: $color-text-muted;
margin-bottom: 12rpx;
}
.required {
color: #f56c6c;
}
.picker-value {
display: flex;
align-items: center;
justify-content: space-between;
height: 72rpx;
padding: 0 20rpx;
background: $color-bg-page;
border-radius: $radius-md;
font-size: 28rpx;
color: $color-text;
}
.dt-row {
display: flex;
gap: 16rpx;
}
.dt-picker {
flex: 1;
min-width: 0;
}
.channel-grid {
display: flex;
flex-wrap: wrap;
gap: 16rpx;
}
.channel-chip {
padding: 12rpx 28rpx;
border-radius: 32rpx;
background: $color-bg-page;
border: 1rpx solid $color-border;
font-size: 26rpx;
color: $color-text;
&.active {
background: rgba(37, 99, 235, 0.08);
border-color: $color-primary;
color: $color-primary;
font-weight: 600;
}
&.disabled {
opacity: 0.45;
}
}
.form-tip {
display: block;
font-size: 22rpx;
color: $color-text-muted;
margin-top: 12rpx;
}
.footer {
position: fixed;
left: 0;
right: 0;
bottom: 0;
display: flex;
gap: 20rpx;
padding: 20rpx $page-padding-x;
padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
background: $color-card;
border-top: 1rpx solid $color-border;
box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.04);
}
</style>
+249 -20
View File
@@ -14,20 +14,52 @@
</view>
</view>
<!-- 周历条 -->
<view class="week-card">
<view
v-for="d in weekDays"
:key="d.key"
class="week-item"
@tap="pickWeekDay(d)"
>
<text class="week-name">{{ d.name }}</text>
<!-- 月历(可下拉展开) -->
<view class="cal-card">
<view class="cal-header">
<view class="cal-nav" @tap="switchMonth(-1)">
<FaIcon name="chevron-left" color="#94a3b8" :size="13" />
</view>
<text class="cal-title">{{ monthLabel }}</text>
<view class="cal-nav" @tap="switchMonth(1)">
<FaIcon name="chevron-right" color="#94a3b8" :size="13" />
</view>
<view class="cal-toggle" @tap="monthOpen = !monthOpen">
<text class="cal-toggle-text">{{ monthOpen ? '收起' : '展开月历' }}</text>
<FaIcon :name="monthOpen ? 'chevron-up' : 'chevron-down'" color="#2563eb" :size="12" />
</view>
</view>
<!-- 周历条 -->
<view class="week-strip">
<view
class="week-date"
:class="{ today: d.isToday, selected: d.key === selectedKey }"
>{{ d.day }}</view>
<view class="week-dot" :class="{ show: d.count > 0 }" />
v-for="d in weekDays"
:key="d.key"
class="week-item"
@tap="pickWeekDay(d)"
>
<text class="week-name">{{ d.name }}</text>
<view
class="week-date"
:class="{ today: d.isToday, selected: d.key === selectedKey }"
>{{ d.day }}</view>
<view class="week-dot" :class="{ show: d.count > 0 }" />
</view>
</view>
<!-- 月历展开 -->
<view v-if="monthOpen" class="month-grid">
<text v-for="n in WEEK_LABELS" :key="'w' + n" class="month-weekname">周{{ n }}</text>
<view
v-for="cell in monthCells"
:key="cell.key"
class="month-day"
:class="{ muted: !cell.inMonth, today: cell.isToday, selected: cell.selected }"
@tap="pickMonthDay(cell)"
>
<view class="month-day-num"><text>{{ cell.day }}</text></view>
<view class="week-dot" :class="{ show: cell.count > 0 }" />
</view>
</view>
</view>
@@ -48,7 +80,7 @@
:text="range === 'week' ? '本周暂无日程提醒' : '当天暂无日程提醒'"
/>
<view v-else class="rem-list">
<view v-for="item in shownItems" :key="item.id" class="rem-card" @tap="openDetail(item.id)">
<view v-for="item in shownItems" :key="item.id" class="rem-card" @tap="openEdit(item.id)">
<view class="rem-time">
<text class="rem-day">{{ shortDayLabel(item.datetime) }}</text>
<text class="rem-clock">{{ timeText(item.datetime) }}</text>
@@ -68,11 +100,18 @@
</view>
<view class="bottom-space" />
<!-- 新增按钮 -->
<view class="fab" @tap="openCreate">
<FaIcon name="plus" color="#ffffff" :size="20" />
<text class="fab-text">新增</text>
</view>
</view>
</template>
<script setup>
import { ref, computed, onMounted } from 'vue'
import { onShow } from '@dcloudio/uni-app'
import { fetchSchedules, getRemindChannelLabel, getRemindMinutesLabel } from '@/api/schedule.js'
import { pad, startOfDay, isToday } from '@/utils/date.js'
import { isLoggedIn } from '@/utils/auth.js'
@@ -99,6 +138,52 @@ function startOfWeek(base = new Date()) {
const weekStart = computed(() => startOfWeek(selectedDate.value))
const selectedKey = computed(() => dateKey(selectedDate.value))
/* ---------- 月历(可下拉展开) ---------- */
const monthOpen = ref(false)
const viewYear = ref(new Date().getFullYear())
const viewMonth = ref(new Date().getMonth()) // 0-based
const monthLabel = computed(() => `${viewYear.value}年${viewMonth.value + 1}月`)
function switchMonth(step) {
let y = viewYear.value
let m = viewMonth.value + step
if (m < 0) {
m = 11
y -= 1
} else if (m > 11) {
m = 0
y += 1
}
viewYear.value = y
viewMonth.value = m
}
/** 月历格子:从包含 1 号的那周周一起,固定 6 行 × 7 列 */
const monthCells = computed(() => {
const first = new Date(viewYear.value, viewMonth.value, 1)
const offset = (first.getDay() + 6) % 7
const start = new Date(viewYear.value, viewMonth.value, 1 - offset)
return Array.from({ length: 42 }, (_, i) => {
const d = new Date(start.getFullYear(), start.getMonth(), start.getDate() + i)
const key = dateKey(d)
return {
key,
date: d,
day: d.getDate(),
inMonth: d.getMonth() === viewMonth.value && d.getFullYear() === viewYear.value,
isToday: isToday(d),
selected: key === selectedKey.value,
count: (reminderMap.value[key] || []).length
}
})
})
function pickMonthDay(cell) {
selectedDate.value = startOfDay(cell.date)
range.value = 'day'
}
/** 只保留已设置提醒渠道的日程 */
const reminders = computed(() =>
schedules.value.filter((item) => item.remindChannels && item.remindChannels.length > 0)
@@ -176,16 +261,24 @@ function remindLine(item) {
function pickWeekDay(d) {
selectedDate.value = startOfDay(d.date)
viewYear.value = d.date.getFullYear()
viewMonth.value = d.date.getMonth()
range.value = 'day'
}
function showToday() {
selectedDate.value = startOfDay(new Date())
viewYear.value = selectedDate.value.getFullYear()
viewMonth.value = selectedDate.value.getMonth()
range.value = 'day'
}
function openDetail(id) {
uni.navigateTo({ url: `/pages/tools/schedule/detail?id=${id}` })
function openEdit(id) {
uni.navigateTo({ url: `/pages/tools/schedule/reminder-edit?id=${id}` })
}
function openCreate() {
uni.navigateTo({ url: '/pages/tools/schedule/reminder-edit' })
}
onMounted(() => {
@@ -196,6 +289,12 @@ onMounted(() => {
loadReminders()
})
// 新增/编辑返回后刷新列表
onShow(() => {
if (!isLoggedIn()) return
if (schedules.value.length || !loading.value) loadReminders()
})
async function loadReminders() {
loading.value = true
try {
@@ -271,16 +370,66 @@ async function loadReminders() {
justify-content: center;
}
/* ---------- 周历条 ---------- */
.week-card {
display: flex;
/* ---------- 月历(可下拉展开) ---------- */
.cal-card {
margin-top: 20rpx;
padding: 20rpx 8rpx 16rpx;
padding: 12rpx 8rpx 16rpx;
background: $color-card;
border-radius: $radius-lg;
box-shadow: $shadow-card;
}
.cal-header {
position: relative;
display: flex;
align-items: center;
justify-content: center;
gap: 20rpx;
padding: 8rpx 16rpx 12rpx;
}
.cal-nav {
display: flex;
align-items: center;
padding: 8rpx 12rpx;
&:active {
opacity: 0.6;
}
}
.cal-title {
min-width: 170rpx;
text-align: center;
font-size: 28rpx;
font-weight: 600;
color: $color-text;
}
.cal-toggle {
position: absolute;
right: 8rpx;
display: flex;
align-items: center;
gap: 6rpx;
padding: 8rpx 12rpx;
&:active {
opacity: 0.6;
}
}
.cal-toggle-text {
font-size: 24rpx;
color: $color-primary;
}
/* ---------- 周历条 ---------- */
.week-strip {
display: flex;
padding: 8rpx 8rpx 4rpx;
}
.week-item {
flex: 1;
display: flex;
@@ -327,6 +476,62 @@ async function loadReminders() {
}
}
/* ---------- 月历网格 ---------- */
.month-grid {
display: flex;
flex-wrap: wrap;
margin-top: 8rpx;
padding: 8rpx 8rpx 0;
border-top: 1rpx solid $color-divider;
}
.month-weekname {
width: calc(100% / 7);
text-align: center;
font-size: 22rpx;
color: $color-text-muted;
padding: 10rpx 0;
}
.month-day {
width: calc(100% / 7);
display: flex;
flex-direction: column;
align-items: center;
gap: 4rpx;
padding: 8rpx 0;
}
.month-day-num {
width: 52rpx;
height: 52rpx;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-size: 26rpx;
color: $color-text;
}
.month-day.today .month-day-num {
color: $color-primary;
font-weight: 600;
}
.month-day.selected .month-day-num {
background: $color-primary;
color: #ffffff;
font-weight: 600;
}
.month-day.muted .month-day-num {
color: #c4cbd6;
}
.month-day:active {
opacity: 0.6;
}
/* ---------- 我的日程 ---------- */
.section-head {
display: flex;
@@ -438,4 +643,28 @@ async function loadReminders() {
.bottom-space {
height: 60rpx;
}
/* ---------- 新增按钮 ---------- */
.fab {
position: fixed;
right: 32rpx;
bottom: calc(48rpx + env(safe-area-inset-bottom));
display: flex;
align-items: center;
gap: 10rpx;
padding: 22rpx 36rpx;
border-radius: 44rpx;
background: $color-primary;
box-shadow: 0 12rpx 28rpx rgba(37, 99, 235, 0.36);
&:active {
opacity: 0.88;
}
}
.fab-text {
font-size: 28rpx;
color: #ffffff;
font-weight: 600;
}
</style>