| | |
| | | * @author Tevin |
| | | */ |
| | | |
| | | import { Fetcher } from './Fetcher'; |
| | | import { Tools } from '@components/common/Tools'; |
| | | import project from '@project'; |
| | | |
| | | export class Pilot { |
| | | |
| | | constructor() { |
| | |
| | | } |
| | | if (/^\$/.test(name)) { |
| | | if (name === '$data' && typeof dataAdd !== 'undefined') { |
| | | // 转换 dataAdd 中 assets 属性下的图片地址值 |
| | | if (typeof dataAdd.assets !== 'undefined') { |
| | | dataAdd.assets = this._transDataAdd(dataAdd.assets); |
| | | } |
| | | // 当有传data值进来,初始值必须带data中的字段 |
| | | const dataOrig = this.$data(); |
| | | options.data = () => { |
| | | return { |
| | | ...dataOrig, |
| | | ...dataAdd, |
| | | } |
| | | } |
| | | }; |
| | | }; |
| | | } else { |
| | | options[name.replace('$', '')] = this[name]; |
| | | } |
| | |
| | | return options; |
| | | } |
| | | |
| | | _transDataAdd(assets = {}) { |
| | | const assets2 = {}; |
| | | Object.keys(assets).forEach(key => { |
| | | let asset = ''; |
| | | if (assets[key].indexOf('assets') > 0) { |
| | | asset = assets[key].split('assets')[1]; |
| | | } else { |
| | | asset = assets[key].replace(/^[.\/\\]*/, '/'); |
| | | } |
| | | // 网页 |
| | | if (process.env.TARO_ENV === 'h5') { |
| | | assets2[key] = project.host.assetsPath + asset; |
| | | } |
| | | // 小程序 |
| | | else if (process.env.TARO_ENV === 'weapp') { |
| | | assets2[key] = Fetcher.host + project.host.assetsPath + asset; |
| | | } |
| | | }); |
| | | return assets2; |
| | | } |
| | | |
| | | } |