Commit ec0ec7b0 by 张立顺

image 组件优化

1 parent f79467f4
/**
* 申请门店开通
*/
// import api from '~/utils/request/request'
// const serverApi = {
// productByscene:'scrm.api.busassistant.activity.productByscene'
// }
// export const productBysceneApi = (data) =>{
// return api.post(
// {
// method: serverApi.productByscene,
// ...data
// },
// true
// )
// }
...@@ -8,7 +8,16 @@ Component({ ...@@ -8,7 +8,16 @@ Component({
properties: { properties: {
src: { src: {
type: String, type: String,
value: '' value: '',
observer: function (url, o) {
if (url) {
let isWebp = url.includes('webp')
this.setData({
isWebp,
imagePath: `${IMG_URL}${url}?v=` + IMG_VERSION()
})
}
}
}, },
mode: { mode: {
type: String, type: String,
...@@ -24,19 +33,20 @@ Component({ ...@@ -24,19 +33,20 @@ Component({
* 组件的初始数据 * 组件的初始数据
*/ */
data: { data: {
imagePath: '' imagePath: '',
isWebp: false
}, },
// 组件生命周期 // 组件生命周期
lifetimes: { lifetimes: {
// 在组件实例进入页面节点树时执行 // 在组件实例进入页面节点树时执行
attached: function () { // attached: function () {
let src = this.data.src // let src = this.data.src
let prefix = IMG_URL // let prefix = IMG_URL
this.setData({ // this.setData({
imagePath: `${prefix}${src}?v=` + IMG_VERSION() // imagePath: `${prefix}${src}?v=` + IMG_VERSION()
}) // })
}, // },
// 在组件实例被从页面节点树移除时执行 // 在组件实例被从页面节点树移除时执行
detached: function () {} detached: function () {}
}, },
......
<!--components/image/index.wxml-->
<image src="{{imagePath}}" mode="{{mode}}" webp="{{webp}}" lazy-load class="custom-class class"></image>
\ No newline at end of file \ No newline at end of file
<!-- components/image/index.wxml -->
<image
src="{{imagePath}}"
mode="{{mode}}"
webp="{{webp||isWebp}}"
lazy-load
class="custom-class class" />
// pages/mineDetail/messageBox/messageBox.js // pages/mineDetail/messageBox/messageBox.js
import mineApi from '~/api/mineApi/index' import mineApi from '~/api/mineApi/index'
// import { handleCopy } from '~/utils/utils_wx' // import { handleCopy } from '~/utils/utils_wx'
let drawQrcode = require('~/utils/lib/weapp-qrcode.js') // let drawQrcode = require('~/utils/lib/weapp-qrcode.js')
import drawQrcode from '~/utils/lib/weapp-qrcode.js'
Component({ Component({
/** /**
* 组件的属性列表 * 组件的属性列表
......
// pages/tab/mine/mine.js // pages/tab/mine/mine.js
import { IMG_URL } from '~/utils/constantData' // import { IMG_URL } from '~/utils/constantData'
import USERAPI from '~/api/usersApi/index' import USERAPI from '~/api/usersApi/index'
import mineApi from '~/api/mineApi/index' import mineApi from '~/api/mineApi/index'
const IMAGES = Object.freeze({ const IMAGES = Object.freeze({
icon0: `${IMG_URL}/personal/icon1.png`, icon0: `/personal/icon1.png`,
icon1: `${IMG_URL}/personal/icon2.png`, icon1: `/personal/icon2.png`,
userAvatarUrl: `${IMG_URL}/personal/userAvatarUrl.png` userAvatarUrl: `/personal/userAvatarUrl.png`
}) })
Page({ Page({
/** /**
...@@ -14,12 +14,13 @@ Page({ ...@@ -14,12 +14,13 @@ Page({
data: { data: {
navStyle: 'background-color: rgba(0,0,0,0);', navStyle: 'background-color: rgba(0,0,0,0);',
IMAGES, IMAGES,
isRead: false isRead: false,
test: `/personal/icon2.png`
}, },
navGO(e) { navGO(e) {
let { path } = e.currentTarget.dataset let { path } = e.currentTarget.dataset
console.log(path) // console.log(path)
wx.$router.go('packagesList.customerManagement') wx.$router.go(path)
}, },
logout() { logout() {
let _this = this let _this = this
...@@ -56,7 +57,8 @@ Page({ ...@@ -56,7 +57,8 @@ Page({
.then(result => { .then(result => {
console.log(result) console.log(result)
this.setData({ this.setData({
isRead: result isRead: result,
test: `/personal/icon2.png`
}) })
}) })
.catch(err => { .catch(err => {
......
<!-- pages/tab/output/output.wxml --> <!-- pages/tab/output/output.wxml -->
<!-- <navigation-bar navStyle="{{navStyle}}">服务商账号名称</navigation-bar> <navigation-bar navStyle="{{navStyle}}" bindnavbarReady="navbarReady">我的账号</navigation-bar>
<view class="layout">
</view> -->
<navigation-bar navStyle="{{navStyle}}" bindnavbarReady="navbarReady">
我的账号
<!-- <picker
range="{{merchantRange}}"
value="{{subIndex}}"
range-key="merchantName"
bindchange="changePicker"
bindtap="tapPicker"
bindcancel="tapPicker"
disabled="{{merchantRange.length < 2}}">
<view class="navigation-title">
<view class="navigation-title-text text-hide">{{merchantRange[subIndex].merchantName}}</view>
<view class="arrow {{moveArrow?'move':''}}" wx:if="{{merchantRange.length > 1}}">
<image src="{{${IMG_URL}/output/arrow.png}}" />
</view>
</view>
</picker> -->
</navigation-bar>
<view class="layout" style="padding-top:{{tabBarStyle}}px;"> <view class="layout" style="padding-top:{{tabBarStyle}}px;">
<view class="userInfoCon"> <view class="userInfoCon">
<image class="headPortrait" src="{{userInfo.userAvatarUrl||IMAGES.userAvatarUrl }}" webp> <glsx-image class="headPortrait" src="{{userInfo.userAvatarUrl||IMAGES.userAvatarUrl }}" webp>
头像 头像
</image> </glsx-image>
<view class="name">{{userInfo.merchantName}}</view> <view class="name">{{userInfo.merchantName}}</view>
<view class="id">账号:{{userInfo.merchantId}}</view> <view class="id">账号:{{userInfo.merchantId}}</view>
<view class="createTime">创建时间:{{userInfo.createdDate}}</view> <view class="createTime">创建时间:{{userInfo.createdDate}}</view>
...@@ -34,14 +13,16 @@ ...@@ -34,14 +13,16 @@
<view class="boxItemCon"> <view class="boxItemCon">
<view class="item" data-path="packagesList.customerManagement" bind:tap="navGO"> <view class="item" data-path="packagesList.customerManagement" bind:tap="navGO">
<view class="imgcon"> <view class="imgcon">
<image class="img" src="{{IMAGES.icon0}}" /> <glsx-image class="img" src="{{IMAGES.icon0}}" />
</view> </view>
<view class="name">客户管理</view> <view class="name">客户管理</view>
</view> </view>
<view class="item" data-path="packagesList.messageBox" bind:tap="navGO"> <view class="item" data-path="packagesList.messageBox" bind:tap="navGO">
<view class="imgcon"> <view class="imgcon">
<view class="redPot" hidden="{{!isRead}}" /> <view class="redPot" hidden="{{!isRead}}" />
<image class="img" src="{{IMAGES.icon1}}" /> <!-- <image class="img" src="{{IMAGES.icon1}}" /> -->
<glsx-image class="img" src="{{test}}" />
<!-- <image class="img" src="{{IMAGES.icon1}}" /> -->
</view> </view>
<view class="name">消息盒子</view> <view class="name">消息盒子</view>
</view> </view>
......
const _routeHooks = Symbol('_routeHooks') const _routeHooks = Symbol('_routeHooks')
const _query = Symbol('_query') const _query = Symbol('_query')
const _routerList = Symbol('_routerList') const _routerList = Symbol('_routerList')
import { IMG_URL, IMG_VERSION } from '~/utils/constantData' // import { IMG_URL, IMG_VERSION } from '~/utils/constantData'
import { generateRoutList } from './wxOnAppRoute.js' import { generateRoutList } from './wxOnAppRoute.js'
import { getNavigationBarTitleText } from '~/utils/cache/storageApi' import { getNavigationBarTitleText } from '~/utils/cache/storageApi'
import { getUserInfo } from '~/utils/cache/userInfo' import { getUserInfo } from '~/utils/cache/userInfo'
...@@ -17,7 +17,7 @@ class Router { ...@@ -17,7 +17,7 @@ class Router {
console.log(e) console.log(e)
console.log(thisPage) console.log(thisPage)
if (thisPage) { if (thisPage) {
thisPage.setData({ IMG_URL, img_version: IMG_VERSION() }) // thisPage.setData({ IMG_URL, img_version: IMG_VERSION() })
if (Object.keys(this[_query]).length) if (Object.keys(this[_query]).length)
thisPage.options = { thisPage.options = {
...thisPage.options, ...thisPage.options,
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!