路泰科技体检小程序UI设计新版本
1
wwl
5 天以前 a6cdbcfe28fcc40ebb4919f57d60fb20122e8e57
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/**
 * @fileoverview 递归子组件,用于显示节点树
 */
Component({
  data: {
    ctrl: {}, // 控制信号
    // #ifdef MP-WEIXIN
    isiOS: wx.getSystemInfoSync().system.includes('iOS')
    // #endif
  },
  properties: {
    childs: Array, // 子节点列表
    opts: Array // 设置 [是否开启懒加载, 加载中占位图, 错误占位图, 是否使用长按菜单]
  },
  options: {
    addGlobalClass: true
  },
  // #ifndef MP-TOUTIAO
  attached () {
    // #ifndef MP-ALIPAY
    this.triggerEvent('add', this, {
      bubbles: true,
      composed: true
    })
    // #endif
    // #ifdef MP-ALIPAY
    this.props.onAdd(this)
    // #endif
  },
  // #endif
  methods: {
    noop () { },
    /**
     * @description 获取标签
     * @param {String} path 路径
     */
    getNode (path) {
      try {
        const nums = path.split('_')
        let node = this.properties.childs[nums[0]]
        for (let i = 1; i < nums.length; i++) {
          node = node.children[nums[i]]
        }
        return node
      } catch {
        return {
          text: '',
          attrs: {},
          children: []
        }
      }
    },
    /**
     * @description 播放视频事件
     * @param {Event} e
     */
    play (e) {
      const i = e.target.dataset.i
      const node = this.getNode(i)
      this.root.triggerEvent('play', {
        source: node.name,
        attrs: {
          ...node.attrs,
          src: node.src[this.data.ctrl[i] || 0]
        }
      })
      if (this.root.properties.pauseVideo) {
        let flag = false
        const id = e.target.id
        for (let i = this.root._videos.length; i--;) {
          if (this.root._videos[i].id === id) {
            flag = true
          } else {
            this.root._videos[i].pause() // 自动暂停其他视频
          }
        }
        // 将自己加入列表
        if (!flag) {
          const ctx = wx.createVideoContext(id
            // #ifndef MP-BAIDU
            , this
            // #endif
          )
          ctx.id = id
          if (this.root.playbackRate) {
            ctx.playbackRate(this.root.playbackRate)
          }
          this.root._videos.push(ctx)
        }
      }
    },
 
    /**
     * @description 图片点击事件
     * @param {Event} e
     */
    imgTap (e) {
      const node = this.getNode(e.target.dataset.i)
      // 父级中有链接
      if (node.a) return this.linkTap(node.a)
      if (node.attrs.ignore) return
      this.root.triggerEvent('imgtap', node.attrs)
      if (this.root.properties.previewImg) {
        const current =
          // #ifndef MP-ALIPAY
          this.root.imgList[node.i]
        // #endif
        // #ifdef MP-ALIPAY
        node.i // eslint-disable-line
        // #endif
        // 自动预览图片
        wx.previewImage({
          // #ifdef MP-WEIXIN
          showmenu: this.root.properties.showImgMenu,
          // #endif
          // #ifdef MP-ALIPAY
          enablesavephoto: this.root.properties.showImgMenu,
          enableShowPhotoDownload: this.root.properties.showImgMenu,
          // #endif
          current,
          urls: this.root.imgList
        })
      }
    },
 
    /**
     * @description 图片加载完成事件
     * @param {Event} e
     */
    imgLoad (e) {
      const i = e.target.dataset.i
      const node = this.getNode(i)
      let val
      if (!node.w) {
        val = e.detail.width
      } else if ((this.properties.opts[1] && !this.data.ctrl[i]) || this.data.ctrl[i] === -1) {
        // 加载完毕,取消加载中占位图
        val = 1
      }
      if (val
        // #ifdef MP-TOUTIAO
        && val !== this.data.ctrl[i] // eslint-disable-line
        // #endif
      ) {
        this.setData({
          ['ctrl.' + i]: val
        })
      }
      this.checkReady()
    },
 
    /**
     * @description 检查是否所有图片加载完毕
     */
    checkReady () {
      if (!this.root.properties.lazyLoad) {
        this.root.imgList._unloadimgs -= 1
        if (!this.root.imgList._unloadimgs) {
          setTimeout(() => {
            this.root.getRect().then(rect => {
              this.root.triggerEvent('ready', rect)
            }).catch(() => {
              this.root.triggerEvent('ready', {})
            })
          }, 350)
        }
      }
    },
 
    /**
     * @description 链接点击事件
     * @param {Event} e
     */
    linkTap (e) {
      const node = e.currentTarget ? this.getNode(e.currentTarget.dataset.i) : {}
      const attrs = node.attrs || e
      const href = attrs.href
      this.root.triggerEvent('linktap', Object.assign({
        innerText: this.root.getText(node.children || []) // 链接内的文本内容
      }, attrs))
      if (href) {
        if (href[0] === '#') {
          // 跳转锚点
          this.root.navigateTo(href.substring(1)).catch(() => { })
        } else if (href.split('?')[0].includes('://')) {
          // 复制外部链接
          if (this.root.properties.copyLink) {
            wx.setClipboardData({
              data: href,
              success: () =>
                wx.showToast({
                  title: '链接已复制'
                })
            })
          }
        } else {
          // 跳转页面
          wx.navigateTo({
            url: href,
            fail () {
              wx.switchTab({
                url: href,
                fail () { }
              })
            }
          })
        }
      }
    },
 
    /**
     * @description 错误事件
     * @param {Event} e
     */
    mediaError (e) {
      const i = e.target.dataset.i
      const node = this.getNode(i)
      if (node.name === 'video' || node.name === 'audio') {
        // 加载其他源
        let index = (this.data.ctrl[i] || 0) + 1
        if (index > node.src.length) {
          index = 0
        }
        if (index < node.src.length) {
          return this.setData({
            ['ctrl.' + i]: index
          })
        }
      } else if (node.name === 'img') {
        // 显示错误占位图
        if (this.properties.opts[2]) {
          this.setData({
            ['ctrl.' + i]: -1
          })
        }
        this.checkReady()
      }
      if (this.root) {
        this.root.triggerEvent('error', {
          source: node.name,
          attrs: node.attrs,
          errMsg: e.detail.errMsg
        })
      }
    }
  }
})