Commit 22528b4f by 胡悦

优化图片

1 parent af923572
......@@ -29,6 +29,9 @@ App({
wx.$router = router
wx.$imgUrl = 'https://img02.glsx.com.cn/weapp/resource/miniprogram/ai-card/'
wx.$appId = wx.getAccountInfoSync().miniProgram.appId
wx.imageCanvas = wx.createOffscreenCanvas({
type: '2d'
})
const systemInfo = wx.$storage.get('aicard_system_info')
if (!systemInfo)
wx.getSystemInfo({
......
......@@ -3,7 +3,7 @@
* @Author: huyue
* @Date: 2022-08-30 11:26:21
* @LastEditors: huyue
* @LastEditTime: 2022-10-28 10:51:40
* @LastEditTime: 2022-11-23 15:21:05
*/
// pages/tab/index/index.js
import { menuMixin } from "../../../mixins/index";
......@@ -11,6 +11,7 @@ import Draw from "../../../utils/Draw";
import { ssoApi, entmicroApi } from "../../../api/api";
import util from "../../../utils/util";
import { trackData } from "../../../utils/data";
Page({
behaviors: [menuMixin],
/**
......@@ -59,14 +60,27 @@ Page({
image: 'https://img.zcool.cn/community/01e47e60ab5b4011013eaf70962e3f.jpg@520w_390h_1c_1e_2o_100sh.jpg',
qrCode: 'https://img.zcool.cn/community/01e47e60ab5b4011013eaf70962e3f.jpg@520w_390h_1c_1e_2o_100sh.jpg'
},
banner: ['company-img3.png', 'company-img31.png'],
banner: ['company-img3', 'company-img31'],
current: 0,
clueList: ['clue-img2.webp', 'clue-img3.webp', 'clue-img4.webp', 'clue-img5.webp', 'clue-img6.webp', 'clue-img7.webp', 'clue-img8.webp', 'clue-img9.webp', 'clue-img10.webp', 'clue-img11.webp', 'clue-img12.webp', 'clue-img13.webp'],
clueCurrent: 0,
awardBanner: [{src: 'company-img7.png', name: '组织荣誉'}, {src: 'company-img71.png', name: '行业奖项'}],
awardCurrent: 0,
shareDisabled: true,
autoplay: true
autoplay: true,
imageObj: {
'company-img1': false,
'bg1': false,
'bg2': false,
'company-img2': false,
'company-img3': false,
'company-img5': false,
'company-img6': false,
'company-img7': false,
'company-img21': false,
'company-img31': false,
'company-img71': false
}
},
introduce(e) {
const curTabIndex = e.currentTarget.dataset.index;
......@@ -184,6 +198,8 @@ Page({
clueCurrent: clueCurrent
})
},
/**
* 生命周期函数--监听页面加载
......@@ -203,8 +219,30 @@ Page({
wx.hideShareMenu({
menus: ['shareAppMessage']
})
this.getImageList()
},
// 获取原图
getImageList() {
const _this = this
let arr = Object.keys(this.data.imageObj)
let list = arr.map(async (item) => {
return await util.getImage(item)
})
console.log(arr)
Promise.allSettled(list).then(result => {
console.log(result)
result.forEach((item, index) => {
if (item.status == 'fulfilled') {
console.log(index)
const name = `imageObj.${arr[index]}`
_this.setData({
[name]: true
})
console.log(name, this.data.imageObj)
}
})
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
......
......@@ -27,7 +27,7 @@
</view>
<!-- 公司介绍 -->
<block wx:if="{{curTabIndex === 0 }}">
<template is="company" data="{{IMGURL, banner, current, img_version, awardBanner, awardCurrent, autoplay}}"></template>
<template is="company" data="{{IMGURL, banner, current, img_version, awardBanner, awardCurrent, autoplay, imageObj}}"></template>
</block>
<!-- 方案介绍 -->
<block wx:if="{{curTabIndex === 1 }}">
......
<!-- 公司介绍 -->
<template name="company">
<view>
<image mode="widthFix" class="img" webp src="{{IMGURL}}image/company/company-img1.png?v={{img_version}}"></image>
<image mode="widthFix" class="img" webp src="{{IMGURL}}image/company/{{imageObj['company-img1'] ? 'company-img1' : 'compress-company-img1'}}.png?v={{img_version}}"></image>
<!-- 合同客户 -->
<view class="relative">
<image mode="widthFix" class="img" webp src="{{IMGURL}}image/company/bg1.png?v={{img_version}}"></image>
<image mode="widthFix" class="img" webp src="{{IMGURL}}image/company/{{imageObj['bg1'] ? 'bg1' : 'compress-bg1'}}.png?v={{img_version}}"></image>
<view class="box2">
<swiper class="swiper" autoplay="{{autoplay}}" duration="5000" interval="5000" circular>
<swiper-item class="swiper-item">
<image class="box2-content" webp src="{{IMGURL}}image/company/company-img2.png?v={{img_version}}"></image>
<image class="box2-content" webp src="{{IMGURL}}image/company/{{imageObj['company-img2'] ? 'company-img2' : 'compress-company-img2'}}.png?v={{img_version}}"></image>
</swiper-item>
<swiper-item class="swiper-item">
<image class="box2-content" webp src="{{IMGURL}}image/company/company-img21.png?v={{img_version}}"></image>
<image class="box2-content" webp src="{{IMGURL}}image/company/{{imageObj['company-img21'] ? 'company-img21' : 'compress-company-img21'}}.png?v={{img_version}}"></image>
</swiper-item>
</swiper>
</view>
</view>
<!-- 政府与行业资质 -->
<view class="relative">
<image mode="widthFix" class="img" webp src="{{IMGURL}}image/company/bg2.png?v={{img_version}}"></image>
<image mode="widthFix" class="img" webp src="{{IMGURL}}image/company/{{imageObj['bg2'] ? 'bg2' : 'compress-bg2'}}.png?v={{img_version}}"></image>
<view class="box3">
<swiper class="box3-swiper" autoplay="{{autoplay}}" bindchange="changePage" current="{{current}}" indicator-dots="{{false}}" indicator-color="#E6E7EB" indicator-active-color="#5850FF" interval="5000" circular>
<block wx:for="{{banner}}" wx:key="ind">
<swiper-item class="swiper-item">
<image class="box3-img" webp src="{{IMGURL}}image/company/{{item}}?v={{img_version}}"></image>
<image class="box3-img" webp src="{{IMGURL}}image/company/{{imageObj[item] ? item : 'compress-' + item}}.png?v={{img_version}}"></image>
</swiper-item>
</block>
</swiper>
......@@ -37,7 +37,7 @@
<!-- 荣誉及奖项 -->
<view class="relative box5">
<image class="box5-title" webp src="{{IMGURL}}image/company/company-img6.png?v={{img_version}}"></image>
<swiper class="box5-swiper" autoplay bindchange="changeBanner" current="{{awardCurrent}}" indicator-dots="{{false}}" indicator-color="#E6E7EB" indicator-active-color="#5850FF" interval="5000" circular>
<swiper class="box5-swiper" autoplay="{{autoplay}}" bindchange="changeBanner" current="{{awardCurrent}}" indicator-dots="{{false}}" indicator-color="#E6E7EB" indicator-active-color="#5850FF" interval="5000" circular>
<block wx:for="{{awardBanner}}" wx:key="ind">
<swiper-item class="swiper-item">
<image class="box5-content" webp src="{{IMGURL}}image/company/{{item.src}}?v={{img_version}}"></image>
......@@ -53,6 +53,6 @@
</view>
<!-- <image mode="widthFix" class="img" src="{{IMGURL}}image/company/company-img5.png?v={{img_version}}"></image> -->
<image mode="widthFix" webp class="img" src="{{IMGURL}}image/company/company-img5.png?v={{img_version}}"></image>
<image mode="widthFix" webp class="img" src="{{IMGURL}}image/company/{{imageObj['company-img5'] ? 'company-img5' : 'compress-company-img5'}}.png?v={{img_version}}"></image>
</view>
</template>
\ No newline at end of file
......@@ -251,6 +251,17 @@ const getSessionId = () => {
const setSessionId = sessionId => {
wx.setStorageSync('aicard_sessionId', sessionId)
}
/** 利用离屏画布获取原图 */
const getImage = (name) => {
console.log(name)
// const imageContext = imageCanvas.getContext('2d')
const image = wx.imageCanvas.createImage()
new Promise(resolve => {
image.onload = resolve(true)
image.src = `${wx.$imgUrl}image/company/${name}.png?v=${new Date()}`
})
}
const removeSystemStorage = () => {
wx.removeStorageSync('aicard_user_info')
wx.removeStorageSync('aicard_sessionId')
......@@ -509,5 +520,6 @@ const Util = {
deepClone,
isEmptyObj,
parseString,
getImage
}
export default Util
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!