| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- import {
- startPhoneListener,
- stopPhoneListener,
- checkIsAutoRecord,
- toCallAutoRecorderPage,
- navigateToCallRecordingSettings,
- jumpToPermissionPage,
- makePhoneCall,
- allRecorderFilesAction
- } from '@/uni_modules/yao-lister';
- import permision from "@/js_sdk/wa-permission/permission.js";
- export default {
- namespaced: true,
- state: {
- filelist: [],
- isAutoRecord: false, // 通话自动录音状态
- hasStoragePermission: false, // 文件访问权限状态
- hasReadPhoneStatePermission: false, // 读取手机状态权限
- hasCallPhonePermission: false, // 拨打电话权限
- hasReadCallLogPermission: false, // 读取通话记录权限
- hasReadPhoneNumbersPermission: false, // 读取电话号码权限
- form: {
- clueId: undefined,
- fileUrl : undefined,
- fileName : undefined,
- type : '3',
- list : [],
- caller : '',
- callee : ''
- },
- },
- mutations: {
- SET_FILE_LIST: (state, data) => {
- state.filelist = data.data
- },
- SET_AUTO_RECORD: (state, value) => {
- state.isAutoRecord = value;
- },
- SET_STORAGE_PERMISSION: (state, value) => {
- state.hasStoragePermission = value;
- },
- SET_READ_PHONE_STATE_PERMISSION: (state, value) => {
- state.hasReadPhoneStatePermission = value;
- },
- SET_CALL_PHONE_PERMISSION: (state, value) => {
- state.hasCallPhonePermission = value;
- },
- SET_READ_CALL_LOG_PERMISSION: (state, value) => {
- state.hasReadCallLogPermission = value;
- },
- SET_READ_PHONE_NUMBERS_PERMISSION: (state, value) => {
- state.hasReadPhoneNumbersPermission = value;
- },
- },
- actions: {
- getFileList({dispatch,state, commit}) {
- dispatch("checkStoragePermission").then(()=>{
- if(state.hasStoragePermission){
- allRecorderFilesAction(res => {
- if(res && res.length > 0) {
- // 将文件路径数组转换为包含filePath和fileName的对象数组
- const fileListPromise = res.map(filePath => {
- return new Promise((resolve) => {
- // 从路径中提取文件名
- const fileName = filePath.split('/').pop();
-
- // 获取文件信息,包括创建时间
- plus.io.resolveLocalFileSystemURL(filePath, (entry) => {
- entry.getMetadata((metadata) => {
- resolve({
- filePath: filePath,
- fileName: fileName,
- createTime: metadata.modificationTime ? metadata.modificationTime : 0, // 文件创建时间
- });
- }, (error) => {
- // 如果获取metadata失败,返回基本信息
- resolve({
- filePath: filePath,
- fileName: fileName,
- createTime: 0, // 设为0,排序时会在最前面
- });
- });
- }, (error) => {
- // 如果解析文件路径失败,返回基本信息
- resolve({
- filePath: filePath,
- fileName: fileName,
- createTime: 0,
- size: 0
- });
- });
- });
- });
-
- // 等待所有文件信息获取完成后进行排序
- Promise.all(fileListPromise).then((fileList) => {
- // 按创建时间排序,最新的文件排在前面(降序)
- fileList.sort((a, b) => {
- return b.createTime - a.createTime;
- });
-
- // 提交文件列表到state
- commit('SET_FILE_LIST', { data: fileList });
- }).catch((error) => {
- console.error('获取文件列表失败:', error);
- // 即使排序失败,也尝试提交原始列表
- const fallbackFileList = res.map(filePath => {
- const fileName = filePath.split('/').pop();
- return {
- filePath: filePath,
- fileName: fileName
- };
- });
- commit('SET_FILE_LIST', { data: fallbackFileList });
- });
- }
- })
- }else{
- dispatch("requestStoragePermission");
- }
- })
-
- },
- // 检查所有权限状态
- checkAllPermissions({ commit }) {
- return new Promise((resolve, reject) => {
- try {
- // 检查通话自动录音状态
- const autoRecordStatus = checkIsAutoRecord();
- commit('SET_AUTO_RECORD', autoRecordStatus);
- // 检查文件访问权限
- this.dispatch('call/checkStoragePermission').then(storagePermission => {
- commit('SET_STORAGE_PERMISSION', storagePermission);
- // 检查其他权限
- const permissions = [
- {
- id: 'android.permission.READ_PHONE_STATE',
- mutation: 'SET_READ_PHONE_STATE_PERMISSION'
- },
- {
- id: 'android.permission.CALL_PHONE',
- mutation: 'SET_CALL_PHONE_PERMISSION'
- },
- {
- id: 'android.permission.READ_CALL_LOG',
- mutation: 'SET_READ_CALL_LOG_PERMISSION'
- },
- {
- id: 'android.permission.READ_PHONE_NUMBERS',
- mutation: 'SET_READ_PHONE_NUMBERS_PERMISSION'
- }
- ];
- const permissionPromises = permissions.map(perm => {
- return permision.requestAndroidPermission(perm.id).then(result => {
- commit(perm.mutation, result === 1);
- return { id: perm.id, granted: result === 1 };
- });
- });
- Promise.all(permissionPromises).then(results => {
- resolve({
- autoRecordStatus,
- storagePermission,
- permissions: results
- });
- });
- });
- } catch (error) {
- reject(error);
- }
- });
- },
- // 检查文件访问权限
- checkStoragePermission({ commit }) {
- return new Promise((resolve) => {
- let hasPermission = false;
- try {
- // 获取Android版本号
- let androidVersion = 0;
- uni.getSystemInfo({
- success: (res) => {
- if (res.system && res.system.includes('Android')) {
- const versionMatch = res.system.match(/Android (\d+\.?\d*)/);
- if (versionMatch && versionMatch[1]) {
- androidVersion = parseFloat(versionMatch[1]);
- }
- }
- if (androidVersion >= 11) {
- // Android 11及以上版本,使用MANAGE_EXTERNAL_STORAGE权限
- const Environment = plus.android.importClass('android.os.Environment');
- hasPermission = Environment.isExternalStorageManager();
- commit('SET_STORAGE_PERMISSION', hasPermission);
- resolve(hasPermission);
- } else {
- // Android 11以下版本,使用READ_EXTERNAL_STORAGE权限
- permision.requestAndroidPermission('android.permission.READ_EXTERNAL_STORAGE')
- .then(result => {
- hasPermission = result === 1;
- commit('SET_STORAGE_PERMISSION', hasPermission);
- resolve(hasPermission);
- });
- }
- }
- });
- } catch (e) {
- hasPermission = false;
- commit('SET_STORAGE_PERMISSION', hasPermission);
- resolve(hasPermission);
- }
- });
- },
- // 请求文件访问权限
- requestStoragePermission() {
- jumpToPermissionPage();
- },
- // 跳转到通话录音设置页面
- toCallRecorderSettings() {
- toCallAutoRecorderPage();
- },
- // 跳转到系统通话录音界面
- toSystemRecorderSettings() {
- navigateToCallRecordingSettings();
- },
- // 打开系统设置
- handleOpenSet() {
- permision.gotoAppPermissionSetting('android.permission.RECORD_AUDIO');
- }
- },
- }
|