更新uniapp和platform

This commit is contained in:
hero920103 committed 2026-11-16 11:32:16 +08:00
1 parent 31ae07175d
commit 7f9a66da0f
47 files changed
+5207 -1974

No files matched your search

+166 -30
View File
@@ -181,7 +181,7 @@
<AppTabbar v-if="!embedded" :group="slug" current="home" />
<!-- 常用功能选择器:从当前子系统可用功能中勾选 -->
<!-- 常用功能选择器:勾选 + 拖动手柄排序(顺序即首页宫格展示顺序) -->
<view v-if="pickerVisible" class="picker-mask" @tap="pickerVisible = false">
<view class="picker-sheet" @tap.stop>
<view class="picker-head">
@@ -189,23 +189,41 @@
<text class="picker-title">选择常用功能</text>
<text class="picker-save" @tap="savePicker">完成</text>
</view>
<text class="picker-tip">最多选 {{ QUICK_MAX }} 个,按点选顺序展示</text>
<text class="picker-tip">最多选 {{ QUICK_MAX }} 个,排在前 {{ QUICK_MAX }} 个会显示在首页;按住右侧手柄拖动可调整</text>
<scroll-view class="picker-body" scroll-y>
<view v-if="quickCandidates.length === 0" class="picker-empty">
<view v-if="pickerItems.length === 0" class="picker-empty">
当前子系统暂无可添加的功能
</view>
<!-- 整份列表:前 pickerSelectedCount 个为已选(高亮 + 序号),拖进/拖出前 N 个即加入/移出常用功能 -->
<view
v-for="(item, index) in quickCandidates"
v-for="(item, index) in pickerItems"
:key="item.id"
class="picker-item"
class="picker-row"
:class="{ on: index < pickerSelectedCount, dragging: dragId === item.id }"
:style="dragRowStyle(item)"
@tap="togglePick(item.id)"
>
<view class="tint-icon picker-icon" :class="item.locked ? 'tint-off' : 'tint-' + (index % 8)">
<FaIcon :name="item.icon || fallbackIcon" color="#ffffff" :size="16" />
</view>
<text class="picker-name">{{ item.title }}</text>
<view class="picker-check" :class="{ on: pickedSet.has(item.id) }">
<FaIcon v-if="pickedSet.has(item.id)" name="check" color="#ffffff" :size="12" />
<view class="picker-state">
<text v-if="index < pickerSelectedCount" class="picker-num">{{ index + 1 }}</text>
<view v-else class="picker-check" />
</view>
<view
class="picker-handle"
@tap.stop="noop"
@touchstart.stop="onDragStart($event, item)"
@touchmove.stop.prevent="onDragMove"
@touchend.stop="onDragEnd"
@touchcancel.stop="onDragEnd"
>
<FaIcon
name="grip-vertical"
:color="dragId === item.id ? '#2563eb' : '#c3cbd9'"
:size="14"
/>
</view>
</view>
</scroll-view>
@@ -288,25 +306,105 @@ const quickMenus = computed(() => {
})
// ============ 常用功能选择器(末位「+」) ============
// 单一列表模型:pickerIds 为全部可选功能的顺序,前 pickerSelectedCount 个即「已选」,
// 也就是首页宫格展示的常用功能——拖动改变顺序时,进出前 N 个即自动加入/移出常用功能。
const pickerVisible = ref(false)
const pickerSelected = ref([])
const pickedSet = computed(() => new Set(pickerSelected.value))
const pickerIds = ref([])
const pickerSelectedCount = ref(0)
/** 选择器列表(按当前顺序渲染全部功能) */
const pickerItems = computed(() => {
const byId = {}
quickCandidates.value.forEach((m) => { byId[m.id] = m })
return pickerIds.value.map((id) => byId[id]).filter(Boolean)
})
function openPicker() {
pickerSelected.value = quickMenus.value.map((m) => m.id)
resetDrag()
const picked = quickMenus.value.map((m) => m.id).slice(0, QUICK_MAX)
const pickedSet = new Set(picked)
const rest = quickCandidates.value.map((m) => m.id).filter((id) => !pickedSet.has(id))
pickerIds.value = picked.concat(rest)
pickerSelectedCount.value = picked.length
pickerVisible.value = true
}
/** 点整行:已选→移出到已选区之后;未选→插到已选区末尾(最多 QUICK_MAX 个) */
function togglePick(id) {
const i = pickerSelected.value.indexOf(id)
if (i >= 0) pickerSelected.value.splice(i, 1)
else {
if (pickerSelected.value.length >= QUICK_MAX) {
const ids = pickerIds.value.slice()
const i = ids.indexOf(id)
if (i < 0) return
if (i < pickerSelectedCount.value) {
ids.splice(i, 1)
ids.splice(Math.max(0, pickerSelectedCount.value - 1), 0, id)
pickerSelectedCount.value = Math.max(0, pickerSelectedCount.value - 1)
} else {
if (pickerSelectedCount.value >= QUICK_MAX) {
uni.showToast({ title: `最多添加 ${QUICK_MAX} 个常用功能`, icon: 'none' })
return
}
pickerSelected.value.push(id)
ids.splice(i, 1)
ids.splice(pickerSelectedCount.value, 0, id)
pickerSelectedCount.value += 1
}
pickerIds.value = ids
}
// ---- 列表拖动排序 ----
// 行高与样式 .picker-row 的 height 保持同一数值;拖动只作用于右侧手柄,
// 手柄上 catchtouchmove 阻止 scroll-view 跟随滚动,因此不会与列表滚动冲突。
const SORT_ROW_RPX = 100
const dragId = ref(null)
const dragOffset = ref(0)
let dragStartY = 0
let dragRowH = 1
let dragFromIndex = -1
/** 拖拽行跟随手指的残余位移(其余行由数组重排自然换位) */
function dragRowStyle(item) {
if (dragId.value !== item.id) return ''
return `transform: translateY(${dragOffset.value}px);`
}
function noop() {}
function onDragStart(e, item) {
const touch = (e.touches && e.touches[0]) || {}
const from = pickerIds.value.indexOf(item.id)
if (from < 0) return
dragStartY = Number(touch.clientY || 0)
dragRowH = uni.upx2px(SORT_ROW_RPX) || 1
dragFromIndex = from
dragOffset.value = 0
dragId.value = item.id
}
function onDragMove(e) {
if (dragId.value === null || dragFromIndex < 0) return
const touch = (e.touches && e.touches[0]) || {}
const delta = Number(touch.clientY || 0) - dragStartY
const last = pickerIds.value.length - 1
const target = Math.max(0, Math.min(last, dragFromIndex + Math.round(delta / dragRowH)))
const cur = pickerIds.value.indexOf(dragId.value)
if (cur >= 0 && target !== cur) {
const ids = pickerIds.value.slice()
ids.splice(cur, 1)
ids.splice(target, 0, dragId.value)
pickerIds.value = ids
}
// 抵消已经跨过的整行位移,剩余部分让行跟着手指走;越界时限制在一行内
const residual = delta - (target - dragFromIndex) * dragRowH
dragOffset.value = Math.max(-dragRowH, Math.min(dragRowH, residual))
}
function resetDrag() {
dragId.value = null
dragOffset.value = 0
dragFromIndex = -1
}
function onDragEnd() {
resetDrag()
}
async function savePicker() {
@@ -314,7 +412,7 @@ async function savePicker() {
await request({
url: '/api/quick-menus',
method: 'POST',
data: { menu_ids: pickerSelected.value }
data: { menu_ids: pickerIds.value.slice(0, pickerSelectedCount.value) }
})
clearHomeCache()
await load(true)
@@ -791,6 +889,7 @@ onShow(() => {
.picker-tip {
padding: 18rpx $page-padding-x 4rpx;
font-size: 22rpx;
line-height: 1.5;
color: $color-text-muted;
}
@@ -808,12 +907,56 @@ onShow(() => {
color: $color-text-muted;
}
.picker-item {
/* 行高固定,拖动排序按行高换算目标位置;改这里需同步 SORT_ROW_RPX */
.picker-row {
position: relative;
display: flex;
align-items: center;
gap: 20rpx;
padding: 22rpx 0;
gap: 18rpx;
height: 100rpx;
box-sizing: border-box;
padding: 0 0 0 16rpx;
border-bottom: 1rpx solid $color-divider;
/* 前 N 个(已选)高亮,拖动进出即加入/移出常用功能 */
&.on {
background: #f2f7ff;
}
&.dragging {
z-index: 3;
background: #ffffff;
border-radius: 16rpx;
border-bottom-color: transparent;
box-shadow: 0 10rpx 26rpx rgba(15, 23, 42, 0.14);
}
}
.picker-state {
width: 40rpx;
flex-shrink: 0;
display: flex;
align-items: center;
justify-content: center;
}
.picker-num {
font-size: 22rpx;
font-weight: 600;
color: $color-primary;
}
.picker-handle {
width: 64rpx;
height: 100rpx;
flex-shrink: 0;
display: flex;
align-items: center;
justify-content: center;
&:active {
opacity: 0.55;
}
}
.picker-icon {
@@ -831,20 +974,13 @@ onShow(() => {
text-overflow: ellipsis;
}
/* 未选中行:空心圆(点击整行加入常用功能) */
.picker-check {
width: 40rpx;
height: 40rpx;
width: 36rpx;
height: 36rpx;
border-radius: 50%;
border: 2rpx solid #c7cede;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
&.on {
background: $color-primary;
border-color: $color-primary;
}
box-sizing: border-box;
}
.err-box {