图片优化

This commit is contained in:
小李 2026-06-30 14:11:18 +08:00
parent ccdab994a8
commit 597ace78aa
32 changed files with 598 additions and 528 deletions

View File

@ -8,10 +8,10 @@
<view class="button-container">
<button class="btn-save-image" @click="saveImage">保存图片</button>
</view>
<l-painter isCanvasToTempFilePath @success="successImage" @progress="progress" hidden
<l-painter isCanvasToTempFilePath @success="successImage" @progress="progress" hidden v-if="data.bgImage"
:css="`width:${data.width}px;height:${data.width / 4 * 3}px;`">
<l-painter-view
:css="`position: relative;width:${data.width}px;height:${data.width / 4 * 3}px;background-image: url('/static/image/other/gzd.png');`">
:css="`position: relative;width:${data.width}px;height:${data.width / 4 * 3}px;background-image: url('${data.bgImage}');`">
<!-- 头部年月 -->
<l-painter-view :css="`position: absolute;left:480px;top:336px;`">
<l-painter-text :css="data.textCssTime" :text="data.form.year" />
@ -183,7 +183,7 @@
<script setup>
//
import ZdyNavbar from "@/components/nav-bar/nav-bar.vue"
import { imgLocal } from '@/utils/common.js';
import {
ref,
reactive,
@ -207,6 +207,7 @@ const data = reactive({
title: "工资条",
bgColor: '#EDEDED',
},
bgImage:'',
width: 375,
height: 495,
code: '',
@ -248,7 +249,7 @@ function progress(e){
if(e==1){
uni.hideLoading()
}
console.log(e)
// console.log(e)
}
//
function edit() {
@ -437,7 +438,7 @@ function saveImage() {
}
}
onLoad((option) => {
onLoad(async(option) => {
//
proxy.$apiUserEvent('all', {
type: 'event',
@ -445,6 +446,9 @@ onLoad((option) => {
prefix: '.uni.other.',
value: "工资单"
})
data.bgImage = await imgLocal.getLocalImage('other/gzd.png');
console.log(data.bgImage)
})
onReady(() => {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 861 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 280 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 332 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 335 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 292 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 307 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 327 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 692 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 253 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 254 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 216 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 225 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 156 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 268 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 278 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 262 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 249 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 610 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 203 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 732 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 460 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 652 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 219 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 133 KiB

View File

@ -261,7 +261,7 @@ export const stringUtil = {
* @returns {string} 唯一ID
*/
uuid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
const r = Math.random() * 16 | 0;
const v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
@ -486,7 +486,7 @@ export const util = {
timingFunc: 'easeIn'
}
})
setTimeout(function () {
setTimeout(function() {
uni.setNavigationBarColor({
animation: { // 动画效果
duration: 100,
@ -619,7 +619,72 @@ export const randomUtil = {
}
};
export const imgLocal = {
simpleHash(str) {
let hash = 0;
for (let i = 0; i < str.length; i++) {
hash = (hash << 5) - hash + str.charCodeAt(i);
hash |= 0;
}
return Math.abs(hash).toString(36);
},
getLocalImage(url) {
return new Promise((resolve, reject) => {
if (!url) return reject('url不能为空');
const CACHE_KEY = 'IMG_CACHE_MAP';
const cache = uni.getStorageSync(CACHE_KEY) || {};
// 🔥 1. 用简单 hash 作为 key避免超长 URL
const key = this.simpleHash(url);
// 2. 命中缓存
if (cache[key]) {
return resolve(cache[key]);
}
const config = uni.getStorageSync('config')
let imgConfig = config.config['client.uniapp.img_path']?.alipay||'http://cdn.u8t.cn/flaunt/uni_mp/img/alipay/static/image/'
url=imgConfig+url
// #ifdef APP-PLUS
const filename = `_doc/img_cache/${key}.jpg`;
const task = plus.downloader.createDownload(
url, {
filename
},
(download, status) => {
if (status === 200) {
const localPath = plus.io.convertLocalFileSystemURL(download.filename);
cache[key] = localPath;
uni.setStorageSync(CACHE_KEY, cache);
resolve(localPath);
} else {
reject('下载失败:' + status);
}
}
);
task.start();
// #endif
// #ifndef APP-PLUS
uni.downloadFile({
url,
success: (res) => {
if (res.statusCode === 200) {
resolve(res.tempFilePath);
} else {
reject('失败');
}
},
fail: reject
});
// #endif
});
}
}
// 默认导出所有工具方法
@ -630,5 +695,6 @@ export default {
...deviceUtil,
...uiUtil,
...util,
...randomUtil
...randomUtil,
...imgLocal
};