index - 副本 (2).vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <template>
  2. <view class="content">
  3. <view class="uni-btn-v uni-common-mt">
  4. <button type="primary" @click="startListerPhone">注册电话监听</button>
  5. <button type="primary" @click="stopListerPhone">注销电话监听</button>
  6. <button type="primary" @click="checkIsAutoRecord">是否开启通话自动录音功能</button>
  7. <button type="primary" @click="toCallAutoRecorderPage">跳转到开启通话自动录音界面</button>
  8. <button type="primary" @click="navigateToCallRecordingSettings">跳转到系统的通话录音界面</button>
  9. <button type="primary" @click="jumpToPermissionPage">请求所有文件访问权限(主要针对ANDROID 11以上获取录音文件需要的权限)</button>
  10. <button type="primary" @click="allRecorderFilesAction">获取通话自动录音文件</button>
  11. <!-- <button type="primary" @click="registerSmsReceiver">注册短信监听</button> -->
  12. <button type="primary" @click="makePhoneCall">拨打电话</button>
  13. </view>
  14. <view class="text-box" scroll-y="true">
  15. <text>{{phoneState}}</text>
  16. </view>
  17. <view v-if="change_pop_show">
  18. <view class="status text-center">蓝牙列表(直接点击连接打印机)</view>
  19. <view class="divider"></view>
  20. <view :class="{ 'popup-height': type === 'left' || type === 'right' }" class="device-list">
  21. <scroll-view scroll-y="true" class="p-content underline">
  22. <view class="underline p-item device-item" hover-class="list-active"
  23. v-for="(item, index) in Filelist" :key="index">
  24. <view class="desc">
  25. {{item}}
  26. </view>
  27. </view>
  28. </scroll-view>
  29. </view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. import {
  35. startPhoneListener,
  36. stopPhoneListener,
  37. checkIsAutoRecord,
  38. toCallAutoRecorderPage,
  39. navigateToCallRecordingSettings,
  40. jumpToPermissionPage,
  41. makePhoneCall,
  42. allRecorderFilesAction,
  43. } from '@/uni_modules/yao-lister';
  44. export default {
  45. data() {
  46. return {
  47. title: 'Hello',
  48. phoneState: '',
  49. stateText: '',
  50. isAndroid: true,
  51. change_pop_show: false,
  52. type: 'center',
  53. Filelist: [],
  54. }
  55. },
  56. mounted() {
  57. this.initPhoneStateListener()
  58. },
  59. beforeDestroy() {
  60. stopListerPhone()
  61. },
  62. methods: {
  63. toggle(type) {
  64. const _this = this;
  65. _this.type = type;
  66. _this.change_pop_show = true;
  67. },
  68. allRecorderFilesAction() {
  69. const _this = this;
  70. allRecorderFilesAction(res => {
  71. console.log("录音文件输入", JSON.stringify(res));
  72. // 录音文件输入, ["/storage/emulated/0/Recordings/Record/Call/15099989786 2025-11-11 09-41-57.m4a","/storage/emulated/0/Recordings/Record/Call/18925012557 2025-11-11 11-10-33.m4a"]
  73. _this.toggle('bottom');
  74. _this.Filelist = res
  75. uni.showToast({
  76. title: JSON.stringify(res),
  77. duration: 2000
  78. })
  79. })
  80. },
  81. jumpToPermissionPage() {
  82. jumpToPermissionPage()
  83. },
  84. navigateToCallRecordingSettings() {
  85. navigateToCallRecordingSettings()
  86. },
  87. toCallAutoRecorderPage() {
  88. toCallAutoRecorderPage()
  89. },
  90. checkIsAutoRecord() {
  91. let checkRecord = checkIsAutoRecord()
  92. uni.showToast({
  93. title: checkRecord ? "已开启电话录音" : "未开启电话录音",
  94. duration: 2000
  95. })
  96. },
  97. makePhoneCall() {
  98. makePhoneCall('15099989786')
  99. // uni.makePhoneCall({
  100. // phoneNumber: '13771854499', // 电话号码
  101. // success: function() {
  102. // console.log('拨打电话成功!');
  103. // },
  104. // fail: function(err) {
  105. // console.error('拨打电话失败:', err);
  106. // }
  107. // });
  108. },
  109. startListerPhone() {
  110. startPhoneListener(res => {
  111. uni.showToast({
  112. icon: 'success',
  113. title: '电话监听开启',
  114. duration: 2000
  115. });
  116. this.phoneState = res + "012"
  117. })
  118. },
  119. stopListerPhone() {
  120. stopPhoneListener(res => {
  121. uni.showToast({
  122. icon: 'success',
  123. title: res,
  124. duration: 2000
  125. });
  126. })
  127. },
  128. async initPhoneStateListener() {
  129. // 动态申请权限
  130. const permissions = ["android.permission.READ_PHONE_STATE",
  131. "android.permission.ANSWER_PHONE_CALLS", "android.permission.CALL_PHONE",
  132. "android.permission.MANAGE_EXTERNAL_STORAGE",
  133. "android.permission.READ_EXTERNAL_STORAGE",
  134. "android.permission.READ_CALL_LOG",
  135. "android.permission.READ_PHONE_NUMBERS",
  136. "android.permission.FOREGROUND_SERVICE"
  137. ]
  138. const result = await plus.android.requestPermissions(permissions, 1001)
  139. if (result.granted) {
  140. startListening()
  141. // 监听原生事件
  142. uni.$on('PHONE_STATE_CHANGE', (state) => {
  143. this.phoneState = state
  144. })
  145. }
  146. }
  147. },
  148. }
  149. </script>
  150. <style>
  151. .text-box {
  152. margin-bottom: 40rpx;
  153. padding: 40rpx 0;
  154. display: flex;
  155. min-height: 300rpx;
  156. background-color: #FFFFFF;
  157. justify-content: center;
  158. align-items: center;
  159. text-align: center;
  160. font-size: 30rpx;
  161. color: #353535;
  162. line-height: 1.8;
  163. border: 1px #007AFF;
  164. height: 200px;
  165. width: 200px;
  166. }
  167. .content {
  168. display: flex;
  169. flex-direction: column;
  170. align-items: center;
  171. justify-content: center;
  172. }
  173. button {
  174. margin: 10px 0;
  175. background-color: #007AFF;
  176. color: white;
  177. }
  178. .logo {
  179. height: 200rpx;
  180. width: 200rpx;
  181. margin-top: 200rpx;
  182. margin-left: auto;
  183. margin-right: auto;
  184. margin-bottom: 50rpx;
  185. }
  186. .text-area {
  187. display: flex;
  188. justify-content: center;
  189. }
  190. .title {
  191. font-size: 36rpx;
  192. color: #8f8f94;
  193. }
  194. .uni-popup {
  195. z-index: 9999;
  196. /* 根据需要调整 */
  197. }
  198. .p-content {
  199. height: calc(70vh - 20px);
  200. width: 700rpx;
  201. }
  202. .text-area {
  203. display: flex;
  204. justify-content: center;
  205. }
  206. .title {
  207. font-size: 36rpx;
  208. color: #8f8f94;
  209. }
  210. .text-center {
  211. display: flex;
  212. justify-content: center;
  213. align-items: center;
  214. }
  215. .desc {
  216. padding-left: 10px;
  217. margin-top: 10px;
  218. }
  219. </style>