callend.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <template>
  2. <view class="call-end-container">
  3. <!-- 有通话信息:显示详细信息 -->
  4. <view class="call-info-card" v-if="hasCallInfo">
  5. <image class="avatar" :src="contactAvatar" mode="aspectFill"></image>
  6. <view class="call-info">
  7. <text class="title">{{ status }}</text>
  8. <text class="contact-name">{{ contactName }}</text>
  9. <view class="duration-info">
  10. <view class="duration-info" v-if="status === '通话已结束' && duration > 0">
  11. <text>通话时长: {{ formatDuration(duration) }}</text>
  12. </view>
  13. </view>
  14. </view>
  15. </view>
  16. <!-- 没有通话信息:显示简单提示 -->
  17. <view class="simple-info" v-else>
  18. <text class="simple-title">通话结束</text>
  19. </view>
  20. <!-- 根据是否有通话信息显示不同按钮 -->
  21. <button class="return-btn" v-if="hasCallInfo" @click="goToHomePage">返回首页</button>
  22. <button class="close-btn" v-else @click="killBackgroundApp">关闭</button>
  23. </view>
  24. </template>
  25. <script>
  26. export default {
  27. data() {
  28. return {
  29. hasCallInfo: false, // 是否有通话信息
  30. contactName: '未知联系人',
  31. contactAvatar: '/static/logo.png',
  32. duration: 0, // 通话时长(秒)
  33. status: '通话已结束',
  34. callType: 'voice' // 'voice' 或 'video'
  35. }
  36. },
  37. onLoad(options) {
  38. // 从路由参数中获取通话信息
  39. if (options && options.name) {
  40. console.log('callend options', options)
  41. this.hasCallInfo = true
  42. this.contactName = decodeURIComponent(options.name) || '未知联系人';
  43. this.contactAvatar = decodeURIComponent(options.avatar) || '/static/logo.png';
  44. this.duration = parseInt(options.duration || 0);
  45. this.status = decodeURIComponent(options.status || '通话已结束');
  46. } else {
  47. console.log('callend 无参数,显示简单模式')
  48. this.hasCallInfo = false
  49. }
  50. console.log('callend 模式:', this.hasCallInfo ? '详细信息' : '简单模式')
  51. },
  52. methods: {
  53. // 格式化通话时长
  54. formatDuration(seconds) {
  55. if (!seconds || seconds <= 0) return '00:00'
  56. const minutes = Math.floor(seconds / 60)
  57. const remainingSeconds = seconds % 60
  58. const formattedMinutes = String(minutes).padStart(2, '0')
  59. const formattedSeconds = String(remainingSeconds).padStart(2, '0')
  60. return `${formattedMinutes}:${formattedSeconds}`
  61. },
  62. // 返回首页
  63. goToHomePage() {
  64. uni.reLaunch({
  65. url: '/pages/device/index'
  66. })
  67. },
  68. // 退出小程序
  69. async killBackgroundApp() {
  70. try {
  71. // 🧹 清理登录信息
  72. uni.removeStorageSync('userInfo')
  73. uni.removeStorageSync('JSESSIONID')
  74. // 🧹 清理通话相关缓存
  75. uni.removeStorageSync('currcall')
  76. uni.removeStorageSync('lastCallInfo')
  77. // 判断是否在真机环境
  78. if (typeof wmpf !== 'undefined') {
  79. await wmpf.Channel.invoke({
  80. command: 'killBackgroundApp',
  81. data: {},
  82. success: (res) => {
  83. uni.showToast({
  84. title: '已退出',
  85. icon: 'success'
  86. });
  87. }
  88. });
  89. } else {
  90. // 开发环境也要清理缓存
  91. uni.showToast({
  92. title: '已退出(开发环境)',
  93. icon: 'success'
  94. });
  95. }
  96. } catch (error) {
  97. console.error('❌ 退出失败:', error);
  98. uni.showToast({
  99. title: '退出失败',
  100. icon: 'error'
  101. });
  102. }
  103. }
  104. }
  105. }
  106. </script>
  107. <style>
  108. .call-end-container {
  109. display: flex;
  110. flex-direction: column;
  111. align-items: center;
  112. justify-content: center;
  113. padding: 40rpx;
  114. min-height: 100vh;
  115. background-color: #f5f5f5;
  116. }
  117. .call-info-card {
  118. width: 90%;
  119. background-color: #fff;
  120. border-radius: 16rpx;
  121. padding: 40rpx;
  122. display: flex;
  123. flex-direction: column;
  124. align-items: center;
  125. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
  126. margin-bottom: 60rpx;
  127. }
  128. .avatar {
  129. width: 160rpx;
  130. height: 160rpx;
  131. border-radius: 50%;
  132. margin-bottom: 30rpx;
  133. border: 4rpx solid #f0f0f0;
  134. }
  135. .call-info {
  136. display: flex;
  137. flex-direction: column;
  138. align-items: center;
  139. width: 100%;
  140. }
  141. .title {
  142. font-size: 36rpx;
  143. font-weight: bold;
  144. color: #333;
  145. margin-bottom: 20rpx;
  146. }
  147. .contact-name {
  148. font-size: 48rpx;
  149. color: #000;
  150. margin-bottom: 30rpx;
  151. font-weight: 500;
  152. }
  153. .duration-info {
  154. display: flex;
  155. align-items: center;
  156. justify-content: center;
  157. font-size: 32rpx;
  158. color: #666;
  159. margin-top: 20rpx;
  160. }
  161. .icon {
  162. width: 32rpx;
  163. height: 32rpx;
  164. margin-right: 10rpx;
  165. }
  166. .simple-info {
  167. display: flex;
  168. flex-direction: column;
  169. align-items: center;
  170. justify-content: center;
  171. padding: 80rpx 40rpx;
  172. }
  173. .simple-title {
  174. font-size: 48rpx;
  175. font-weight: bold;
  176. color: #333;
  177. }
  178. .return-btn {
  179. background-color: #07c160;
  180. color: #fff;
  181. font-size: 36rpx;
  182. padding: 20rpx 0;
  183. width: 90%;
  184. border-radius: 12rpx;
  185. margin-top: 60rpx;
  186. }
  187. .close-btn {
  188. background-color: #ff4d4f;
  189. color: #fff;
  190. font-size: 36rpx;
  191. padding: 20rpx 0;
  192. width: 90%;
  193. border-radius: 12rpx;
  194. margin-top: 60rpx;
  195. }
  196. /* 横屏和竖屏模式的响应式样式 */
  197. @media screen and (orientation: landscape) {
  198. .call-info-card {
  199. flex-direction: row;
  200. align-items: center;
  201. text-align: left;
  202. padding: 30rpx 40rpx;
  203. }
  204. .avatar {
  205. margin-right: 40rpx;
  206. margin-bottom: 0;
  207. }
  208. .call-info {
  209. align-items: flex-start;
  210. }
  211. }
  212. </style>