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AC,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC;IACvC,CAAC;IAED,MAAM;QACJ,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,UAAiB,CAAC;QACvC,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC;QAClB,IAAI,CAAC,GAAG,EAAE;YACR,gBAAgB;YAChB,IAAI,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;SACxC;aAAM;YACL,IAAI,CAAC,OAAO,CAAC;gBACX,SAAS,EAAE,IAAI;gBACf,QAAQ,EAAE,KAAK;aAChB,CAAC,CAAC;SACJ;IACH,CAAC;CACF,CAAA;AAnFoB,KAAK;IADzB,WAAW,EAAE;GACO,KAAK,CAmFzB;eAnFoB,KAAK","file":"image.js","sourcesContent":["import { SuperComponent, wxComponent } from '../common/src/index';\nimport ImageProps from './props';\nimport config from '../common/config';\n\nconst { prefix } = config;\nconst name = `${prefix}-image`;\n@wxComponent()\nexport default class Image extends SuperComponent {\n externalClasses = ['t-class', 't-class-load'];\n\n options = {\n multipleSlots: true,\n };\n\n properties = ImageProps;\n\n data = {\n isLoading: true,\n isFailed: false,\n widthStyle: '', // 自动计算的图片宽度样式(兼容基础库版本2.10.3以下的版本不支持heightFix模式)\n classPrefix: name,\n };\n\n preSrc = ''; // 保留上一次的src,防止在src相同时重复update\n\n lifetimes = {\n attached(this: Image) {\n this.update();\n },\n };\n\n observers = {\n src() {\n if (this.preSrc === this.properties.src) return;\n this.update();\n },\n };\n\n onLoaded(e: any) {\n const sdkVersion = wx.getSystemInfoSync().SDKVersion;\n const versionArray = sdkVersion.split('.').map((v) => parseInt(v, 10));\n // 版本号低于2.10.3时组件内部实现heightFix模式\n if (\n versionArray[0] < 2 ||\n (versionArray[0] === 2 && versionArray[1] < 10) ||\n (versionArray[0] === 2 && versionArray[1] === 10 && versionArray[2] < 3)\n ) {\n const mode = (this.properties.mode as any) as string;\n if (mode === 'heightFix') {\n // 实现heightFix模式,保持高度和宽高比,设置对应的宽度\n const { height: picHeight, width: picWidth } = e.detail;\n const query = this.createSelectorQuery();\n query\n .select('#image')\n .boundingClientRect((res) => {\n const { height } = res;\n const resultWidth = ((height / picHeight) * picWidth).toFixed(2);\n this.setData({ widthStyle: `width: ${resultWidth}px;` });\n })\n .exec();\n }\n }\n this.setData({\n isLoading: false,\n isFailed: false,\n });\n this.triggerEvent('load', e.detail);\n }\n\n onLoadError(e: any) {\n this.setData({\n isLoading: false,\n isFailed: true,\n });\n this.triggerEvent('error', e.detail);\n }\n\n update() {\n const { src } = this.properties as any;\n this.preSrc = src;\n if (!src) {\n // 链接为空时直接触发加载失败\n this.onLoadError({ errMsg: '图片链接为空' });\n } else {\n this.setData({\n isLoading: true,\n isFailed: false,\n });\n }\n }\n}\n"]}