hh-doctor-sdk 0.7.5 → 0.7.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -179,11 +179,11 @@ module.exports = Behavior({
179
179
  }
180
180
 
181
181
  if (caseImageList && caseImageList.length > 0) {
182
- const isVideo = caseImageList[0].imageurl.includes('.mp4')
182
+ const isVideo = caseImageFilter.isVideoUrl(caseImageList[0].imageurl)
183
183
  message.type = isVideo ? MessageTypes.video : MessageTypes.image
184
184
  message.images = caseImageList
185
185
  message.isVideo = isVideo
186
- message.cover = isVideo ? caseImageList[0].imageurl + '?x-oss-process=video/snapshot,t_0,f_jpg' : caseImageList[0].smallImage
186
+ message.cover = isVideo ? caseImageFilter.videoSnapshotUrl(caseImageList[0].imageurl) : caseImageList[0].smallImage
187
187
  message.number = `共${caseImageList.length}${isVideo ? '个' : '张'}`
188
188
  message.template = MessageTemplates.image
189
189
 
@@ -58,7 +58,7 @@ module.exports = Behavior({
58
58
  videoGroupList.forEach(videosInGroup => {
59
59
  const unit = '个'
60
60
  const fileType = 4
61
- let thumb = videosInGroup[0].url + '?x-oss-process=video/snapshot,t_0,f_jpg'
61
+ let thumb = videosInGroup[0].thumb
62
62
  const showNumber = !['HISINFO', 'METER'].includes(type.toUpperCase()) ? `共${videosInGroup.length}${unit}` : '点击查看'
63
63
  mediaGroups.push(this.mediaItem(groupIndex, fileType, name, videosInGroup, thumb, showNumber))
64
64
  groupIndex++
@@ -6,6 +6,7 @@ var audioAnimationInterval
6
6
  const hhNavigation = require('../../hh-navigation')
7
7
  const doctorLoader = require('../../public/doctor-loader')
8
8
  const permission = require('../../utils/permission-utils')
9
+ const { urlEndsWith } = require('../../utils/common-utils')
9
10
 
10
11
  Page({
11
12
 
@@ -119,7 +120,7 @@ Page({
119
120
  _playAudio(event) {
120
121
  const url = event.currentTarget.dataset.url
121
122
  const index = event.currentTarget.dataset.index
122
- const playerUrl = `${url}${url.endsWith('.amr') ? '.mp3' : ''}`
123
+ const playerUrl = `${url}${urlEndsWith(url, '.amr') ? '.mp3' : ''}`
123
124
  const same = playerUrl == currentPlayUrl
124
125
  this._stopPlayAudio()
125
126
  if (same) {
@@ -1,3 +1,18 @@
1
+ const { urlEndsWith, appendUrlQuery } = require('../../../utils/common-utils')
2
+
3
+ function isVideoUrl(url) {
4
+ return urlEndsWith(url, '.mp4')
5
+ }
6
+
7
+ function isPdfUrl(url) {
8
+ return urlEndsWith(url, '.pdf')
9
+ }
10
+
11
+ /** 视频封面:OSS 截帧,兼容已带签名参数的 URL */
12
+ function videoSnapshotUrl(url) {
13
+ return appendUrlQuery(url, 'x-oss-process=video/snapshot,t_0,f_jpg')
14
+ }
15
+
1
16
  /**
2
17
  * 获取媒体数据中的图片数据列表,单条数据格式如下:
3
18
  *
@@ -6,15 +21,16 @@
6
21
  * @param {*} caseImageList 媒体数据原始列表
7
22
  */
8
23
  function imageList(caseImageList) {
9
- const images = caseImageList.filter((value, index, array) => {
24
+ const images = caseImageList.filter((value) => {
10
25
  console.log(JSON.stringify(value))
11
- if (value.s3key && value.s3key.length > 0) {
12
- return !value.s3key.endsWith('.pdf') && !value.s3key.endsWith('.mp4')
26
+ const key = value.s3key
27
+ if (key && key.length > 0) {
28
+ return !isPdfUrl(key) && !isVideoUrl(key)
13
29
  }
14
- return value.imageurl && !value.imageurl.includes('.pdf') && !value.imageurl.includes('.mp4')
30
+ return value.imageurl && !isPdfUrl(value.imageurl) && !isVideoUrl(value.imageurl)
15
31
  })
16
32
 
17
- const imageDataList = images.map((value, index, array) => {
33
+ const imageDataList = images.map((value) => {
18
34
  const imageurl = value.imageurl
19
35
  return {
20
36
  type: 'image',
@@ -33,19 +49,20 @@ function imageList(caseImageList) {
33
49
  * @param {*} caseImageList 媒体数据原始列表
34
50
  */
35
51
  function videoList(caseImageList) {
36
- const videos = caseImageList.filter((value, index, array) => {
37
- if (value.s3key && value.s3key.length > 0) {
38
- return value.s3key.endsWith('.mp4')
52
+ const videos = caseImageList.filter((value) => {
53
+ const key = value.s3key
54
+ if (key && key.length > 0) {
55
+ return isVideoUrl(key)
39
56
  }
40
- return value.imageurl && value.imageurl.includes('.mp4')
57
+ return isVideoUrl(value.imageurl)
41
58
  })
42
59
 
43
- const imageDataList = videos.map((value, index, array) => {
60
+ const imageDataList = videos.map((value) => {
44
61
  const imageurl = value.imageurl
45
62
  return {
46
63
  type: 'video',
47
64
  url: imageurl,
48
- thumb: imageurl + '?x-oss-process=video/snapshot,t_0,f_jpg'
65
+ thumb: videoSnapshotUrl(imageurl)
49
66
  }
50
67
  })
51
68
  return imageDataList
@@ -59,13 +76,14 @@ function videoList(caseImageList) {
59
76
  * @param {*} caseImageList 媒体数据原始列表
60
77
  */
61
78
  function pdfList(caseImageList) {
62
- const pdfs = caseImageList.filter((value, index, array) => {
63
- if (value.s3key && value.s3key.length > 0) {
64
- return value.s3key.endsWith('.pdf')
79
+ const pdfs = caseImageList.filter((value) => {
80
+ const key = value.s3key
81
+ if (key && key.length > 0) {
82
+ return isPdfUrl(key)
65
83
  }
66
- return value.imageurl && value.imageurl.includes('.pdf')
84
+ return isPdfUrl(value.imageurl)
67
85
  })
68
- return pdfs.map((value, index, arary) => {
86
+ return pdfs.map((value) => {
69
87
  return pdfData(value.imageurl, value.imagedesc)
70
88
  })
71
89
  }
@@ -124,5 +142,8 @@ module.exports = {
124
142
  videoList,
125
143
  pdfList,
126
144
  mediaGroupList,
127
- pdfGroupList
128
- }
145
+ pdfGroupList,
146
+ isVideoUrl,
147
+ isPdfUrl,
148
+ videoSnapshotUrl
149
+ }
@@ -53,6 +53,7 @@ async function isDoctorAuth(doctorId) {
53
53
  // const haveLicense = (doctorInfo.superLicenseUrl && doctorInfo.superLicenseUrl.length > 0) || (doctorInfo.superLicense1Url && doctorInfo.superLicense1Url.length > 0);
54
54
  // return isAuthHH && haveLicense;
55
55
  }
56
+
56
57
  return false;
57
58
  } catch {
58
59
  return false;
@@ -57,6 +57,48 @@ function getLinkName(link) {
57
57
  return '点此前往'
58
58
  }
59
59
 
60
+ /**
61
+ * 去掉 query/hash 后判断路径是否以指定扩展名结尾(兼容带签名参数的 URL)
62
+ * @param {string} url
63
+ * @param {string} ext 如 '.mp4'
64
+ */
65
+ function urlEndsWith(url, ext) {
66
+ if (!url || !ext) {
67
+ return false
68
+ }
69
+ let path = url
70
+ const q = path.indexOf('?')
71
+ if (q >= 0) {
72
+ path = path.substring(0, q)
73
+ }
74
+ const h = path.indexOf('#')
75
+ if (h >= 0) {
76
+ path = path.substring(0, h)
77
+ }
78
+ return path.toLowerCase().endsWith(ext.toLowerCase())
79
+ }
80
+
81
+ /**
82
+ * 给 URL 追加 query 参数(已有 ? 时用 &,兼容签名 URL)
83
+ * @param {string} url
84
+ * @param {string} query 如 'x-oss-process=video/snapshot,t_0,f_jpg',可带或不带前导 ?/&
85
+ */
86
+ function appendUrlQuery(url, query) {
87
+ if (!url) {
88
+ return url
89
+ }
90
+ if (!query) {
91
+ return url
92
+ }
93
+ const q = String(query).replace(/^[?&]/, '')
94
+ if (!q) {
95
+ return url
96
+ }
97
+ return url + (url.indexOf('?') >= 0 ? '&' : '?') + q
98
+ }
99
+
60
100
  module.exports = {
61
- findLinkFromText
101
+ findLinkFromText,
102
+ urlEndsWith,
103
+ appendUrlQuery
62
104
  }
@@ -27,7 +27,7 @@
27
27
  <view class="item-button" bindtap="_clickViewCase">
28
28
  <image
29
29
  class="item-button-img"
30
- src="http://image.hh-medic.com/icon/pacs/hh_chat_bingli.png"
30
+ src="https://image.hh-medic.com/icon/pacs/hh_chat_bingli.png"
31
31
  mode=""
32
32
  />
33
33
  <view class="control-button-text">病历资料</view>
@@ -115,14 +115,14 @@ module.exports = Behavior({
115
115
  let type = 'image'
116
116
  const url = file.fileUrl
117
117
  let thumb = url
118
- const isVideo = url.endsWith('.mp4')
119
- const isPdf = url.includes('.pdf')
118
+ const isVideo = caseImageFilter.isVideoUrl(url)
119
+ const isPdf = caseImageFilter.isPdfUrl(url)
120
120
  if (isPdf) {
121
121
  type = 'pdf'
122
122
  thumb = 'https://image.hh-medic.com/icon/pacs/hh_icon_pdf.png'
123
123
  } else if (isVideo) {
124
124
  type = 'video'
125
- thumb = `${url}?x-oss-process=video/snapshot,t_0,f_jpg`
125
+ thumb = caseImageFilter.videoSnapshotUrl(url)
126
126
  }
127
127
  const data = {
128
128
  url: url,
@@ -1,6 +1,12 @@
1
1
  /**
2
2
  * 视频铃声
3
3
  */
4
+
5
+ // 真机上 InnerAudioContext 创建后立即 play 偶发不生效,
6
+ // 改为立即播放并在未开始时有限次重试,成功后即停止重试
7
+ const RING_MAX_RETRY = 5
8
+ const RING_RETRY_INTERVAL = 200
9
+
4
10
  module.exports = Behavior({
5
11
  data: {
6
12
  calling: {
@@ -18,27 +24,39 @@ module.exports = Behavior({
18
24
  * 播放呼叫铃声
19
25
  */
20
26
  playCallRing() {
21
- var audioContext = this.data.callingAudioContext
22
- if (!audioContext) audioContext = wx.createInnerAudioContext();
27
+ // 重新发起呼叫,先清理上一次的实例与重试
28
+ this.stopCallRing()
29
+
30
+ const audioContext = wx.createInnerAudioContext()
31
+ audioContext.src = this.data.calling.url
32
+ audioContext.loop = true
23
33
  this.setData({
24
34
  callingAudioContext: audioContext,
25
35
  })
26
- audioContext.stop()
27
- audioContext.src = this.data.calling.url
28
- audioContext.loop = true
29
- setTimeout(() => {
36
+
37
+ // 一旦真正开始播放,立即停止重试
38
+ audioContext.onPlay(() => this._clearRingPlayTimer())
39
+
40
+ let retry = 0
41
+ const tryPlay = () => {
42
+ // 实例已被 stopCallRing 销毁则终止,避免野实例继续播放
43
+ if (this.data.callingAudioContext !== audioContext) return
30
44
  audioContext.play()
31
- }, 300);
45
+ this._ringPlayTimer = setTimeout(() => {
46
+ if (retry++ < RING_MAX_RETRY) tryPlay()
47
+ }, RING_RETRY_INTERVAL)
48
+ }
49
+ tryPlay()
32
50
  },
33
51
  /**
34
52
  * 停止播放呼叫铃声
35
53
  */
36
54
  stopCallRing() {
37
- var audioContext = this.data.callingAudioContext
55
+ this._clearRingPlayTimer()
56
+ const audioContext = this.data.callingAudioContext
38
57
  if (audioContext) {
39
- audioContext.stop();
40
- audioContext.destroy();
41
- audioContext = null
58
+ audioContext.stop()
59
+ audioContext.destroy()
42
60
  this.setData({
43
61
  callingAudioContext: null,
44
62
  })
@@ -49,12 +67,21 @@ module.exports = Behavior({
49
67
  */
50
68
  playHangup() {
51
69
  this.stopCallRing()
52
- let audioContext = wx.createInnerAudioContext({
70
+ const audioContext = wx.createInnerAudioContext({
53
71
  useWebAudioImplement: false
54
72
  })
55
73
  audioContext.src = this.data.hangup.url
56
74
  audioContext.loop = false
57
75
  audioContext.play()
58
76
  },
77
+ /**
78
+ * 清除待执行的重试定时器
79
+ */
80
+ _clearRingPlayTimer() {
81
+ if (this._ringPlayTimer) {
82
+ clearTimeout(this._ringPlayTimer)
83
+ this._ringPlayTimer = null
84
+ }
85
+ },
59
86
  }
60
- })
87
+ })
@@ -65,6 +65,8 @@ Page({
65
65
  * 生命周期函数--监听页面卸载
66
66
  */
67
67
  onUnload() {
68
+ // 兜底:任何路径关闭页面都确保铃声停止,避免残留
69
+ this.stopCallRing()
68
70
  this.unBindIMMessageEvent()
69
71
  wx.hhImManager.destroy()
70
72
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hh-doctor-sdk",
3
- "version": "0.7.5",
3
+ "version": "0.7.8",
4
4
  "description": "和缓名医小程序SDK",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"