index - 副本 (2).vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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('13417106969')
  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. console.log(res,"监听结果==============================")
  112. })
  113. },
  114. stopListerPhone() {
  115. stopPhoneListener(res => {
  116. console.log(res,"3123123123");
  117. uni.showToast({
  118. icon: 'success',
  119. title: res,
  120. duration: 2000
  121. });
  122. })
  123. },
  124. async initPhoneStateListener() {
  125. // 动态申请权限
  126. const permissions = [
  127. "android.permission.READ_PHONE_STATE",
  128. "android.permission.ANSWER_PHONE_CALLS", "android.permission.CALL_PHONE",
  129. "android.permission.MANAGE_EXTERNAL_STORAGE",
  130. "android.permission.READ_EXTERNAL_STORAGE",
  131. "android.permission.READ_CALL_LOG",
  132. "android.permission.READ_PHONE_NUMBERS",
  133. "android.permission.FOREGROUND_SERVICE"
  134. ]
  135. await plus.android.requestPermissions(permissions, 1001)
  136. }
  137. },
  138. }
  139. </script>
  140. <style>
  141. .text-box {
  142. margin-bottom: 40rpx;
  143. padding: 40rpx 0;
  144. display: flex;
  145. min-height: 300rpx;
  146. background-color: #FFFFFF;
  147. justify-content: center;
  148. align-items: center;
  149. text-align: center;
  150. font-size: 30rpx;
  151. color: #353535;
  152. line-height: 1.8;
  153. border: 1px #007AFF;
  154. height: 200px;
  155. width: 200px;
  156. }
  157. .content {
  158. display: flex;
  159. flex-direction: column;
  160. align-items: center;
  161. justify-content: center;
  162. }
  163. button {
  164. margin: 10px 0;
  165. background-color: #007AFF;
  166. color: white;
  167. }
  168. .logo {
  169. height: 200rpx;
  170. width: 200rpx;
  171. margin-top: 200rpx;
  172. margin-left: auto;
  173. margin-right: auto;
  174. margin-bottom: 50rpx;
  175. }
  176. .text-area {
  177. display: flex;
  178. justify-content: center;
  179. }
  180. .title {
  181. font-size: 36rpx;
  182. color: #8f8f94;
  183. }
  184. .uni-popup {
  185. z-index: 9999;
  186. /* 根据需要调整 */
  187. }
  188. .p-content {
  189. height: calc(70vh - 20px);
  190. width: 700rpx;
  191. }
  192. .text-area {
  193. display: flex;
  194. justify-content: center;
  195. }
  196. .title {
  197. font-size: 36rpx;
  198. color: #8f8f94;
  199. }
  200. .text-center {
  201. display: flex;
  202. justify-content: center;
  203. align-items: center;
  204. }
  205. .desc {
  206. padding-left: 10px;
  207. margin-top: 10px;
  208. }
  209. </style>