1 |
- {"version":3,"sources":["../src/image/image.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAe,MAAM,qBAAqB,CAAC;AAOlE,MAAM,CAAC,OAAO,OAAO,KAAM,SAAQ,cAAc;IAC/C,eAAe,WAA+B;IAE9C,OAAO;;MAEL;IAEF,UAAU,gCAAc;IAExB,IAAI;;;;;MAKF;IAEF,MAAM,SAAM;IAEZ,SAAS;uBACQ,KAAK;MAGpB;IAEF,SAAS;;MAKP;IAEF,QAAQ,CAAC,CAAC,EAAE,GAAG;IA+Bf,WAAW,CAAC,CAAC,EAAE,GAAG;IAQlB,MAAM;CAaP","file":"image.d.ts","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"]}
|