From 1bc942e13a091031ca6ce1756f2e2293a7117b15 Mon Sep 17 00:00:00 2001
From: lefengyang <lefengyang@tencent.com>
Date: Mon, 17 Aug 2026 05:56:13 +0800
Subject: [PATCH] 返回按钮放到右下角
---
ledApp/pages/addTemplate/addTemplate.vue | 367 ++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 313 insertions(+), 54 deletions(-)
diff --git a/ledApp/pages/addTemplate/addTemplate.vue b/ledApp/pages/addTemplate/addTemplate.vue
index ba8ff1d..9b9bbc7 100644
--- a/ledApp/pages/addTemplate/addTemplate.vue
+++ b/ledApp/pages/addTemplate/addTemplate.vue
@@ -97,7 +97,22 @@
<view class="footer_none"></view>
<view class="footer_btn">
- <uv-button text="保存" color="linear-gradient( 142deg, #6FD2FF 0%, #268DFF 100%)" shape="circle" @click="clickTempleteAdd()"></uv-button>
+ <uv-button text="预览" color="linear-gradient( 142deg, #6FD2FF 0%, #268DFF 100%)" shape="circle" customStyle="width:40vw;" @click="openPreview"></uv-button>
+ <uv-button text="保存" color="linear-gradient( 142deg, #6FD2FF 0%, #268DFF 100%)" shape="circle" customStyle="width:40vw;" @click="clickTempleteAdd()"></uv-button>
+ </view>
+
+ <!-- 预览浮层 -->
+ <view class="preview_overlay" v-if="previewShow" @click.self="closePreview">
+ <view class="preview_title">预览动画</view>
+ <view class="preview_matrix">
+ <view class="preview_grid" :style="{
+ gridTemplateRows: 'repeat(' + previewHeight + ', auto)',
+ gridTemplateColumns: 'repeat(' + previewWidth + ', auto)'
+ }">
+ <view class="preview_cell" v-for="(cell, idx) in currentPreviewFrame" :key="idx" :style="{ backgroundColor: cell || '#1a1a1a' }"></view>
+ </view>
+ </view>
+ <view class="preview_close_btn" @click="closePreview">关闭</view>
</view>
<!-- 动画帧数 -->
@@ -109,11 +124,16 @@
<!-- 动画弹出框 -->
<uv-popup ref="popupAnimation" mode="center" @change="changeAnimation" :safeAreaInsetTop="false" :safeAreaInsetBottom="false" :zoom="false" duration="0">
<view class="animation_pixel">
- <view class="back_btn" @click="popupAnimationClose">
+ <view class="back_btn" v-show="false" @click="popupAnimationClose">
<uv-icon name="arrow-leftward" color="#333" size="30"></uv-icon>
</view>
+ <!-- 操作按钮 -->
+ <view class="controls" style="left: 30rpx;">
+ <uv-button type="success" :plain="true" :text="showControls ? '返回' : '操作'" @click="toggleControls"></uv-button>
+ </view>
+
<!-- 动画按钮 -->
- <view class="controls">
+ <view class="controls" v-if="showControls">
<uv-button type="primary" :plain="true" text="分辨率" @click="changeRatio()"></uv-button>
<uv-button type="primary" :plain="true" text="颜色" @click="changeColor()"></uv-button>
<uv-button type="primary" :plain="true" text="添加文字" @click="addText()"></uv-button>
@@ -123,16 +143,29 @@
<!-- 文字生成图形 -->
<canvas canvas-id="myCanvas" id="myCanvas" class="canvas" :style="{ width: canvasWidth + 'px', height: canvasHeight + 'px' }"></canvas>
+ <!-- canvasWidth:{{ canvasWidth }} | canvasHeight:{{ canvasHeight }} -->
- <view class="pixel_grid" @touchstart.prevent="handleTouchStart" @touchmove.prevent="handleTouchMove"
- @touchend.prevent="handleTouchEnd" @touchcancel.prevent="handleTouchEnd"
- :style="{
- gridTemplateRows: `repeat(${height}, 1fr)`,
- gridTemplateColumns: `repeat(${width}, 1fr)`
- }">
- <view class="pixel_cell" v-for="(cell, cellIndex) in pixelData" :key="cellIndex">
- <view class="pixel_cell_item" :style="{ backgroundColor: cell }"></view>
+ <!-- 点阵图 -->
+ <scroll-view scroll-x @scroll="handleScroll">
+ <view
+ class="pixel_grid"
+ @touchstart.prevent="handleTouchStart"
+ @touchmove.prevent="handleTouchMove"
+ @touchend.prevent="handleTouchEnd"
+ @touchcancel.prevent="handleTouchEnd"
+ :style="{
+ gridTemplateRows: `repeat(${height}, 1fr)`,
+ gridTemplateColumns: `repeat(${width * (modeVal == 2 ? 10 : 1)}, 1fr)`,
+ width: modeVal == 2 ? '1000vw': '100vw',
+ }">
+ <view class="pixel_cell" v-for="(cell, cellIndex) in pixelData" :key="cellIndex">
+ <view class="pixel_cell_item" :style="{ backgroundColor: cell }"></view>
+ </view>
</view>
+ <view style="height:20vh;"></view>
+ </scroll-view>
+ <view class="exit_btn">
+ <uv-button type="success" :plain="true" text="退出" @click="popupAnimationClose"></uv-button>
</view>
</view>
</uv-popup>
@@ -179,6 +212,10 @@
{
name: '动画帧切换',
val: 1
+ },
+ {
+ name: '滚动动画',
+ val: 2
}
],
modeVal: 0,
@@ -234,8 +271,22 @@
fpsList: [],
tId: '',
tempInfo:{},
- titleName: '新增模版'
-
+ titleName: '新增模版',
+ previewShow: false,
+ previewFrames: [],
+ previewFrameIndex: 0,
+ previewTimer: null,
+ previewWidth: 24,
+ previewHeight: 12,
+ showControls: false,
+ scrollLeft: 0,
+ }
+ },
+ computed: {
+ currentPreviewFrame() {
+ if (this.previewFrames.length === 0) return [];
+ const frame = this.previewFrames[this.previewFrameIndex % this.previewFrames.length];
+ return frame || [];
}
},
onLoad(opt) {
@@ -254,16 +305,21 @@
},
onHide() {
this.$refs.popupAnimation.close();
+ this.stopPreviewAnimation();
if (typeof plus !== 'undefined') {
plus.screen.lockOrientation('portrait')
}
},
onUnload() {
+ this.stopPreviewAnimation();
if (typeof plus !== 'undefined') {
plus.screen.lockOrientation('portrait')
}
},
methods: {
+ handleScroll(e){
+ this.scrollLeft = e.detail.scrollLeft
+ },
// 获取编辑详情
getTempleteInfo(){
templeteInfo(this.tId).then(res=>{
@@ -376,6 +432,15 @@
return this.mergeRowsToString(item)
});
this.fpsTotal = this.total
+ } else if (this.modeVal == 2) {
+ const scrollFrames = this.generateScrollFrames(this.fpsData[0]);
+ const parsedData = scrollFrames.map(item => {
+ return this.toSnakeData(item, this.specWidth);
+ });
+ this.animationData = parsedData.map(item => {
+ return this.mergeRowsToString(item);
+ });
+ this.fpsTotal = scrollFrames.length;
}
console.log('animationData--------', this.animationData)
@@ -475,10 +540,10 @@
console.log('ratio---', ratio[0]);
this.height = Number(ratio[0]);
this.width = Number(ratio[1]);
- this.canvasWidth = this.width * 10;
+ this.canvasWidth = this.width * (this.modeVal == 2 ? 10 * 10 : 10);
this.canvasHeight = this.height * 10;
- // 重新初始化一维数组
- this.pixelData = new Array(this.height * this.width).fill('')
+ const colCount = this.width * (this.modeVal == 2 ? 10 : 1)
+ this.pixelData = new Array(this.height * colCount).fill('')
console.log('pixelData---', this.pixelData);
},
// 预先获取像素网格的位置信息
@@ -496,14 +561,16 @@
getCellByTouch(touch, cb) {
this.getGridRect(rect => {
if (!rect) return
- const x = touch.clientX - rect.left
+ const x = touch.clientX - rect.left + this.scrollLeft
const y = touch.clientY - rect.top
- const cellWidth = rect.width / this.width
+ const colCount = this.width * (this.modeVal == 2 ? 10 : 1)
+ const cellWidth = rect.width / colCount
const cellHeight = rect.height / this.height
const colIndex = Math.floor(x / cellWidth)
const rowIndex = Math.floor(y / cellHeight)
+ console.log('colCount', colCount, 'colIndex', colIndex)
if (
- colIndex >= 0 && colIndex < this.width &&
+ colIndex >= 0 && colIndex < colCount &&
rowIndex >= 0 && rowIndex < this.height
) {
cb({
@@ -543,7 +610,8 @@
handleClick(rowIndex, colIndex) {
console.log(rowIndex, colIndex)
// 计算一维数组的索引
- const index = rowIndex * this.width + colIndex
+ const colCount = this.width * (this.modeVal == 2 ? 10 : 1)
+ const index = rowIndex * colCount + colIndex
// 如果当前像素有颜色,则清除;如果没有颜色,则添加当前选择的颜色
const currentColor = this.pixelData[index]
const newColor = currentColor ? '' : this.color
@@ -551,8 +619,12 @@
},
clear() {
ctx && ctx.clearRect(0, 0, 1000, 1000)
+ const colCount = this.width * (this.modeVal == 2 ? 10 : 1)
// 将所有像素点设置为空字符串
- this.pixelData = new Array(this.height * this.width).fill('')
+ this.pixelData = new Array(this.height * colCount).fill('')
+ },
+ toggleControls() {
+ this.showControls = !this.showControls;
},
// 模版动画弹出框
changeAnimation(e){
@@ -573,10 +645,15 @@
popupAnimationOpen(index){
this.$refs.popupAnimation.open();
this.fpsIndex = index
+ this.canvasWidth = this.width * (this.modeVal == 2 ? 10 * 10 : 10);
if(this.fpsList[this.fpsIndex] == null){
console.log('第一次编辑-----null')
- this.pixelData = new Array(this.height * this.width).fill('')
+ let pointCount = this.height * this.width
+ if (this.modeVal == 2) {
+ pointCount *= 10
+ }
+ this.pixelData = new Array(pointCount).fill('')
}else{
console.log('已编辑过-----')
this.pixelData = this.fpsList[this.fpsIndex]
@@ -585,7 +662,8 @@
// 关闭模版动画
popupAnimationClose(){
this.$refs.popupAnimation.close();
- this.pixelData = new Array(this.height * this.width).fill('')
+ const colCount = this.width * (this.modeVal == 2 ? 10 : 1)
+ this.pixelData = new Array(this.height * colCount).fill('')
},
// 屏幕规格
changeSpec(e) {
@@ -610,6 +688,51 @@
const rowStrings = rows.map(r => r.join('')) // 每行合并
return rowStrings.join('') // 所有行合并
},
+ // 生成滚动动画帧数据(modeVal==2)
+ // 从点阵图左侧开始,按照设定分辨率窗口提取动画帧,每帧左移3个像素,剩余全空时停止
+ generateScrollFrames(data) {
+ const cols = this.specWidth;
+ const rows = this.specHeight;
+ const totalCols = this.specWidth * 10;
+ const step = 3;
+
+ let grid = [];
+ for (let r = 0; r < rows; r++) {
+ grid.push(data.slice(r * totalCols, (r + 1) * totalCols));
+ }
+
+ const frames = [];
+ let offset = 0;
+
+ while (offset < totalCols) {
+ let remainingEmpty = true;
+ for (let r = 0; r < rows; r++) {
+ for (let c = offset; c < totalCols; c++) {
+ if (grid[r][c] !== '' && grid[r][c] !== '000000') {
+ remainingEmpty = false;
+ break;
+ }
+ }
+ if (!remainingEmpty) break;
+ }
+
+ if (remainingEmpty) break;
+
+ let frame = [];
+ for (let r = 0; r < rows; r++) {
+ let row = grid[r].slice(offset, offset + cols);
+ while (row.length < cols) {
+ row.push('000000');
+ }
+ frame = frame.concat(row);
+ }
+
+ frames.push(frame);
+ offset += step;
+ }
+
+ return frames;
+ },
// 生成一帧动画其他帧数据
generateFrames(data, frameCount = 24) {
const cols = this.specWidth; // 每行 24 个
@@ -654,7 +777,8 @@
changeMode(e) {
this.fpsList = []
this.fpsData = []
- if (e == 0) {
+ this.gridRect = null
+ if (e == 0 || e == 2) {
this.total = 1
} else {
this.total = 2
@@ -734,19 +858,24 @@
ctx = uni.createCanvasContext('myCanvas', this);
// 设置字体样式
- ctx.setFontSize(this.canvasHeight * 0.9);
+ ctx.setFontSize(this.canvasHeight);
ctx.setFillStyle('#000')
- ctx.setTextAlign('center')
ctx.setTextBaseline('middle')
// 绘制文字
- // 计算文字位置
- // 水平居中
- const x = this.canvasWidth / 2;
// 垂直居中,稍微向上偏移一点
- const y = this.canvasHeight / 2;
-
- // 绘制文字
- ctx.fillText(char, x, y);
+ const y = this.canvasHeight / 2 + 10;
+
+ if (this.modeVal == 2) {
+ // 滚动动画:文字靠左对齐
+ ctx.setTextAlign('left')
+ const x = 20;
+ ctx.fillText(char, x, y);
+ } else {
+ // 其他模式:文字水平居中
+ ctx.setTextAlign('center')
+ const x = this.canvasWidth / 2;
+ ctx.fillText(char, x, y);
+ }
// 绘制到画布
ctx.draw(false, () => {
@@ -758,18 +887,19 @@
width: this.canvasWidth,
height: this.canvasHeight,
success: (res) => {
- console.log(res)
+ console.log('canvasGetImageData', res)
const imageData = res.data;
// 生成一维数组
- const pixelArray = new Array(this.height * this.width).fill('')
-
+ const colCount = this.width * (this.modeVal == 2 ? 10 : 1)
+ const pixelArray = new Array(this.height * colCount).fill('')
+
// 计算每个格子的像素大小
- const cellWidth = this.canvasWidth / this.width;
+ const cellWidth = this.canvasWidth / colCount;
const cellHeight = this.canvasHeight / this.height;
// 生成一维数组
for (let y = 0; y < this.height; y++) {
- for (let x = 0; x < this.width; x++) {
+ for (let x = 0; x < colCount; x++) {
let blackPixels = 0;
let totalPixels = 0;
@@ -787,7 +917,7 @@
// 计算亮度
const brightness = 0.3 * r + 0.59 * g + 0.11 * b;
-
+
// 如果亮度小于阈值且透明度大于阈值,则认为是黑色
if (brightness < 128 && a > 128) {
blackPixels++;
@@ -795,11 +925,11 @@
totalPixels++;
}
}
-
+
// 如果黑色像素占比超过阈值,则设置为当前选择的颜色
const isBlack = blackPixels / totalPixels > 0.3;
- const arrayIndex = y * this.width + x;
- pixelArray[arrayIndex] = isBlack ? this.color : ''; // 改为颜色值或空字符串
+ const arrayIndex = y * colCount + x;
+ pixelArray[arrayIndex] = isBlack ? this.color : '';
}
}
@@ -813,6 +943,82 @@
});
},
+ openPreview() {
+ if (this.fpsList.length === 0 || this.fpsList.every(f => f === null || f === undefined)) {
+ uni.showToast({
+ title: '请先编辑动画帧',
+ icon: 'none'
+ });
+ return;
+ }
+ this.previewWidth = this.modeVal == 2 ? this.specWidth : this.width;
+ this.previewHeight = this.height;
+ this.previewFrames = this.buildPreviewFrames();
+ this.previewFrameIndex = 0;
+ this.previewShow = true;
+ this.$nextTick(() => {
+ this.startPreviewAnimation();
+ });
+ },
+ closePreview() {
+ this.stopPreviewAnimation();
+ this.previewShow = false;
+ },
+ buildPreviewFrames() {
+ if (this.modeVal == 0) {
+ const data = this.fpsList[0];
+ if (!data) return [];
+ return this.generatePreviewFrames(data, 24);
+ } else if (this.modeVal == 2) {
+ const data = this.fpsList[0];
+ if (!data) return [];
+ return this.generateScrollFrames(data);
+ } else {
+ const frames = [];
+ for (let i = 0; i < this.total; i++) {
+ if (this.fpsList[i] && this.fpsList[i] !== null) {
+ frames.push(this.fpsList[i]);
+ } else {
+ frames.push(new Array(this.width * this.height).fill(''));
+ }
+ }
+ return frames;
+ }
+ },
+ generatePreviewFrames(data, frameCount) {
+ const cols = this.width;
+ const rows = this.height;
+ const frames = [];
+ let grid = [];
+ for (let r = 0; r < rows; r++) {
+ grid.push(data.slice(r * cols, (r + 1) * cols));
+ }
+ for (let f = 0; f < frameCount; f++) {
+ let frame = [];
+ for (let r = 0; r < rows; r++) {
+ let row = grid[r].slice();
+ let shifted = row.slice(f % cols).concat(row.slice(0, f % cols));
+ frame = frame.concat(shifted);
+ }
+ frames.push(frame);
+ }
+ return frames;
+ },
+ startPreviewAnimation() {
+ this.stopPreviewAnimation();
+ if (!this.speed || this.speed <= 0 || this.previewFrames.length === 0) return;
+ const interval = this.speed * 2.8;
+ console.log('interval', interval)
+ this.previewTimer = setInterval(() => {
+ this.previewFrameIndex = (this.previewFrameIndex + 1) % this.previewFrames.length;
+ }, interval);
+ },
+ stopPreviewAnimation() {
+ if (this.previewTimer) {
+ clearInterval(this.previewTimer);
+ this.previewTimer = null;
+ }
+ },
// 修改添加文字方法
async addText() {
uni.showModal({
@@ -880,14 +1086,30 @@
}
}
- .controls {
+ .action_btn {
position: absolute;
bottom: 10px;
left: 50px;
+ z-index: 10;
+ background: linear-gradient(142deg, #6FD2FF 0%, #268DFF 100%);
+ padding: 12px 24px;
+ border-radius: 30px;
+ box-shadow: 0 4px 12px rgba(38, 141, 255, 0.4);
+ }
+ .controls {
+ position: absolute;
+ bottom: 10rpx;
+ left: 110rpx;
display: flex;
- gap: 20px;
+ gap: 10rpx;
z-index: 9;
}
+ .exit_btn{
+ position: absolute;
+ right: 30rpx;
+ bottom: 10rpx;
+ z-index: 9999;
+ }
.animation_pixel{
width: 100vw;
height: 100vh;
@@ -907,11 +1129,8 @@
top: -9999px;
}
.pixel_grid {
- position: fixed;
- left: 0;
- top: var(--status-bar-height);
- right: 0;
- bottom: 0;
+ height: 80vh;
+ border-bottom: 1px solid #eee;
display: grid;
gap: 1px;
box-sizing: border-box;
@@ -950,18 +1169,58 @@
bottom: 0;
background: #fff;
padding: 30rpx 40rpx;
+ display: flex;
+ justify-content: space-between;
}
- .footer_btn2 {
+
+ .preview_overlay {
position: fixed;
+ top: 0;
left: 0;
right: 0;
bottom: 0;
- background: #fff;
- padding: 30rpx 40rpx;
+ background: rgba(0, 0, 0, 0.85);
display: flex;
+ flex-direction: column;
align-items: center;
- justify-content: space-between;
- box-shadow: 0 0 10rpx rgba(0, 0, 0, 0.1);
+ justify-content: center;
+ z-index: 9999;
+ }
+ .preview_title {
+ color: #fff;
+ font-size: 34rpx;
+ margin-bottom: 40rpx;
+ }
+ .preview_matrix {
+ background: #000;
+ padding: 20rpx;
+ border-radius: 16rpx;
+ box-shadow: 0 0 30rpx rgba(0, 150, 255, 0.3);
+ }
+ .preview_grid {
+ display: grid;
+ gap: 2rpx;
+ background: #111;
+ padding: 4rpx;
+ border-radius: 8rpx;
+ }
+ .preview_cell {
+ width: 22rpx;
+ height: 22rpx;
+ border-radius: 50%;
+ background: #1a1a1a;
+ box-shadow: inset 0 0 4rpx rgba(0, 0, 0, 0.5);
+ }
+ .preview_close_btn {
+ margin-top: 60rpx;
+ width: 300rpx;
+ height: 80rpx;
+ line-height: 80rpx;
+ text-align: center;
+ color: #fff;
+ background: linear-gradient(142deg, #6FD2FF 0%, #268DFF 100%);
+ border-radius: 40rpx;
+ font-size: 30rpx;
}
.temp_btn {
--
Gitblit v1.10.0