diff --git a/env/.env.prod b/env/.env.prod index 4a05c95..74a388c 100644 --- a/env/.env.prod +++ b/env/.env.prod @@ -5,17 +5,17 @@ VITE_SHOW_CONSOLE = false # 是否开启sourcemap VITE_SHOW_SOURCEMAP = false -# # baseUrl -# VITE_BASEURL = 'https://chat-out.szjixun.cn' #体制外 -# #VITE_SOCKET_API -# VITE_SOCKET_API = 'wss://chat-out.szjixun.cn' #体制外 -# # EPRAPI baseUrl -# VITE_EPR_BASEURL = 'https://erpapi-out.szjixun.cn' #体制外 - # baseUrl -VITE_BASEURL = 'https://chat.szjixun.cn' #体制内 +VITE_BASEURL = 'https://chat-out.szjixun.cn' #体制外 #VITE_SOCKET_API -VITE_SOCKET_API = 'wss://chat.szjixun.cn' #体制内 +VITE_SOCKET_API = 'wss://chat-out.szjixun.cn' #体制外 # EPRAPI baseUrl -VITE_EPR_BASEURL = 'https://erpapi.fontree.cn' #体制内 +VITE_EPR_BASEURL = 'https://erpapi-out.szjixun.cn' #体制外 + +# # baseUrl +# VITE_BASEURL = 'https://chat.szjixun.cn' #体制内 +# #VITE_SOCKET_API +# VITE_SOCKET_API = 'wss://chat.szjixun.cn' #体制内 +# # EPRAPI baseUrl +# VITE_EPR_BASEURL = 'https://erpapi.fontree.cn' #体制内 diff --git a/env/.env.test b/env/.env.test index dfe98c6..d6e39a6 100644 --- a/env/.env.test +++ b/env/.env.test @@ -4,9 +4,16 @@ NODE_ENV = 'test' VITE_SHOW_CONSOLE = true # 是否开启sourcemap VITE_SHOW_SOURCEMAP = true -# baseUrl + +# # baseUrl VITE_BASEURL = 'http://172.16.100.93:8503' -#VITE_SOCKET_API +# #VITE_SOCKET_API VITE_SOCKET_API = 'ws://172.16.100.93:8504' + +# baseUrl +# VITE_BASEURL = 'http://192.168.88.21:9503' +#VITE_SOCKET_API +# VITE_SOCKET_API = 'ws://192.168.88.21:9504' + # EPRAPI baseUrl VITE_EPR_BASEURL = 'http://114.218.158.24:9020' diff --git a/package.json b/package.json index 5d02326..53e6624 100644 --- a/package.json +++ b/package.json @@ -31,16 +31,17 @@ "@uni-helper/axios-adapter": "^1.5.2", "@uni-helper/localforage-adapter": "^1.0.2", "@uni-helper/uni-use": "^0.19.12", - "@vueuse/core": "^9.13.0", "@vueup/vue-quill": "^1.2.0", - "quill": "^1.3.7", - "quill-mention": "^4.1.0", + "@vueuse/core": "^9.13.0", "axios": "^1.7.2", "dayjs": "^1.11.12", "less": "^4.2.0", "lodash": "^4.17.21", "nzh": "^1.0.13", "pinia-plugin-persistedstate": "^4.1.3", + "quill": "^1.3.7", + "quill-mention": "^4.1.0", + "recorder-core": "^1.3.25011100", "vconsole": "^3.15.1", "vue": "^3.3.8", "vue-i18n": "11.0.0-rc.1" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2d194c2..b718ce7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -92,6 +92,9 @@ importers: quill-mention: specifier: ^4.1.0 version: 4.1.0 + recorder-core: + specifier: ^1.3.25011100 + version: 1.3.25011100 vconsole: specifier: ^3.15.1 version: 3.15.1 @@ -3843,6 +3846,9 @@ packages: resolution: {integrity: sha512-GDhwkLfywWL2s6vEjyhri+eXmfH6j1L7JE27WhqLeYzoh/A3DBaYGEj2H/HFZCn/kMfim73FXxEJTw06WtxQwg==} engines: {node: '>= 14.18.0'} + recorder-core@1.3.25011100: + resolution: {integrity: sha512-trXsCH0zurhoizT4Z22C0OsM0SDOW+2OvtgRxeLQFwxoFeqFjDjYZsbZEZUiKMJLhBvamI4K7Ic+qZ2LBo74TA==} + regenerate-unicode-properties@10.2.0: resolution: {integrity: sha512-DqHn3DwbmmPVzeKj9woBadqmXxLvQoQIwu7nopMc72ztvxVmVk2SBhSnx67zuye5TP+lJsb/TBQsjLKhnDf3MA==} engines: {node: '>=4'} @@ -9393,6 +9399,8 @@ snapshots: readdirp@4.1.2: {} + recorder-core@1.3.25011100: {} + regenerate-unicode-properties@10.2.0: dependencies: regenerate: 1.4.2 diff --git a/src/api/chat/index.js b/src/api/chat/index.js index a405445..45fe6a5 100644 --- a/src/api/chat/index.js +++ b/src/api/chat/index.js @@ -1,9 +1,6 @@ import request from '@/service/index.js' import qs from 'qs' -import { - useTalkStore, - useDialogueStore -} from '@/store' +import { useTalkStore, useDialogueStore } from '@/store' // 获取聊天列表服务接口 export const ServeGetTalkList = (data) => { @@ -44,7 +41,11 @@ export const ServeTopTalkList = (data) => { // 清除聊天消息未读数服务接口 export const ServeClearTalkUnreadNum = (data, unReadNum) => { console.log('=======chatApp==UnreadNum', unReadNum) - if(!useTalkStore().items[useTalkStore().findTalkIndex(useDialogueStore().index_name)]?.is_disturb){ + if ( + !useTalkStore().items[ + useTalkStore().findTalkIndex(useDialogueStore().index_name) + ]?.is_disturb + ) { if (typeof plus !== 'undefined') { let OAWebView = plus.webview.all() OAWebView.forEach((webview) => { @@ -229,4 +230,13 @@ export const ServeMessageReadDetail = (data) => { method: 'POST', data, }) -} \ No newline at end of file +} + +// 语音转文字 +export const ServeConvertText = (data) => { + return request({ + url: '/api/v1/talk/message/voice-to-text', + method: 'POST', + data, + }) +} diff --git a/src/components/deep-bubble/deep-bubble.vue b/src/components/deep-bubble/deep-bubble.vue index d7d8213..fc9572c 100644 --- a/src/components/deep-bubble/deep-bubble.vue +++ b/src/components/deep-bubble/deep-bubble.vue @@ -25,7 +25,15 @@ class="flex flex-col items-center justify-center" > -
复制
+
复制
+ +
+ +
转文字
-
多选
+
多选
-
引用
+
引用
-
撤回
+
撤回
-
删除
+
删除
@@ -78,8 +86,8 @@ // 组件 // uniapp & vue -import { onLoad, onReady } from "@dcloudio/uni-app"; -import { defineEmits, defineProps } from "vue"; +import { onLoad, onReady } from '@dcloudio/uni-app' +import { defineEmits, defineProps } from 'vue' import { reactive, ref, @@ -87,18 +95,18 @@ import { computed, nextTick, getCurrentInstance, - onMounted, - onBeforeUnmount -} from "vue"; -import copy07 from "@/static/image/chatList/copy07@2x.png"; -import multipleChoices from "@/static/image/chatList/multipleChoices@2x.png"; -import cite from "@/static/image/chatList/cite@2x.png"; -import withdraw from "@/static/image/chatList/withdraw@2x.png"; -import delete07 from "@/static/image/chatList/delete@2x.png"; + onMounted, + onBeforeUnmount, +} from 'vue' +import copy07 from '@/static/image/chatList/copy07@2x.png' +import multipleChoices from '@/static/image/chatList/multipleChoices@2x.png' +import cite from '@/static/image/chatList/cite@2x.png' +import withdraw from '@/static/image/chatList/withdraw@2x.png' +import delete07 from '@/static/image/chatList/delete@2x.png' // pinia -const systemInfo = uni.getSystemInfoSync(); -const bubbleRef = ref(null); +const systemInfo = uni.getSystemInfoSync() +const bubbleRef = ref(null) const props = defineProps({ isShowCopy: { @@ -113,109 +121,114 @@ const props = defineProps({ type: Boolean, default: true, }, -}); + isShowConvertText: { + //是否显示转文字 + type: Boolean, + default: false, + }, +}) -const emits = defineEmits(["clickMenu"]); +const emits = defineEmits(['clickMenu']) /** * @name 生成UUID */ const uuid = () => { - const reg = /[xy]/g; - return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx" + const reg = /[xy]/g + return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx' .replace(reg, function (c) { var r = (Math.random() * 16) | 0, - v = c == "x" ? r : (r & 0x3) | 0x8; - return v.toString(16); + v = c == 'x' ? r : (r & 0x3) | 0x8 + return v.toString(16) }) - .replace(/-/g, ""); -}; + .replace(/-/g, '') +} -const popoverBoxId = `ID${uuid()}`; -const popoverContentId = `ID${uuid()}`; -const instance = getCurrentInstance(); +const popoverBoxId = `ID${uuid()}` +const popoverContentId = `ID${uuid()}` +const instance = getCurrentInstance() const data = reactive({ popoverShow: false, defaultStyle: {}, showStyle: { left: 0, - right: "", - transform: "", + right: '', + transform: '', }, iconStyle: { - left: "", - right: "", - transform: "", + left: '', + right: '', + transform: '', }, -}); +}) /** * @name 获取DOM */ const getDom = (dom) => { return new Promise((resolve, reject) => { - const query = uni.createSelectorQuery().in(instance); - let select = query.select(dom); + const query = uni.createSelectorQuery().in(instance) + let select = query.select(dom) const boundingClientRect = select.boundingClientRect((data) => { - resolve(data); - }); - boundingClientRect.exec(); - }); -}; + resolve(data) + }) + boundingClientRect.exec() + }) +} const itemClick = (item) => { - emits("clickMenu", item); -}; + emits('clickMenu', item) +} // 弹起 长按5 -let pressDownTime = 0; -let time = null; +let pressDownTime = 0 +let time = null const onTouchstart = () => { - time && clearTimeout(time); - time = setTimeout(open, 500); -}; + time && clearTimeout(time) + time = setTimeout(open, 500) +} const onTouchend = () => { - time && clearTimeout(time); -}; + time && clearTimeout(time) +} const open = async () => { - let popoverContent = await getDom(`#${popoverContentId}`); - let popoverBox = await getDom(`#${popoverBoxId}`); + let popoverContent = await getDom(`#${popoverContentId}`) + let popoverBox = await getDom(`#${popoverBoxId}`) // 缩放中心点 - let originX = popoverBox.width / 2; + let originX = popoverBox.width / 2 // 根据距离 初始化位置 判断是顶部还是底部 - let isTop = popoverBox.top - 50 > popoverContent.height; + let isTop = popoverBox.top - 50 > popoverContent.height // 上面还是下面 data.defaultStyle = { - top: isTop ? "60rpx" : "auto", - bottom: !isTop ? "-20rpx" : "auto", - transform: `translateY(${isTop ? "-100%" : "100%"}) scale(.8)`, - }; + top: isTop ? '60rpx' : 'auto', + bottom: !isTop ? '-20rpx' : 'auto', + transform: `translateY(${isTop ? '-100%' : '100%'}) scale(.8)`, + } // 左边还是右边 if (popoverBox.left > systemInfo.windowWidth - popoverBox.right) { - data.defaultStyle.right = 0; + data.defaultStyle.right = 0 // 动画缩放中心点 - data.defaultStyle["transform-origin"] = `${ + data.defaultStyle['transform-origin'] = `${ popoverContent.width - originX - }px ${isTop ? "100%" : "0%"}`; + }px ${isTop ? '100%' : '0%'}` } else { - data.defaultStyle.left = 0; + data.defaultStyle.left = 0 // 动画缩放中心点 - data.defaultStyle["transform-origin"] = `${originX}px ${ - isTop ? "100%" : "0%" - }`; + data.defaultStyle['transform-origin'] = `${originX}px ${ + isTop ? '100%' : '0%' + }` } - data.showStyle = { ...data.defaultStyle }; + data.showStyle = { ...data.defaultStyle } // icon位置样式 let iconDefsultStyle = { - transform: `translate(0%, ${isTop ? "20%" : "-20%"})`, - "border-top-color": isTop ? "#333333" : "", - "border-bottom-color": !isTop ? "#333333" : "", - top: !isTop ? "-20rpx" : "auto", - bottom: isTop ? "-20rpx" : "auto", - }; + transform: `translate(0%, ${isTop ? '20%' : '-20%'})`, + 'border-top-color': isTop ? '#333333' : '', + 'border-bottom-color': !isTop ? '#333333' : '', + top: !isTop ? '-20rpx' : 'auto', + bottom: isTop ? '-20rpx' : 'auto', + } setTimeout(() => { if (popoverBox.left > systemInfo.windowWidth - popoverBox.right) { @@ -224,55 +237,55 @@ const open = async () => { ...data.defaultStyle, // 显示 opacity: 1, - transform: `translateY(${isTop ? "-100%" : "100%"}) scale(1)`, - "pointer-events": "auto", - }; + transform: `translateY(${isTop ? '-100%' : '100%'}) scale(1)`, + 'pointer-events': 'auto', + } data.iconStyle = { right: `${originX}px`, - left: "auto", + left: 'auto', ...iconDefsultStyle, - }; + } } else { data.showStyle = { // 位置 ...data.defaultStyle, // 显示 opacity: 1, - transform: `translateY(${isTop ? "-100%" : "100%"}) scale(1)`, - "pointer-events": "auto", - }; + transform: `translateY(${isTop ? '-100%' : '100%'}) scale(1)`, + 'pointer-events': 'auto', + } data.iconStyle = { left: `${originX}px`, - right: "auto", + right: 'auto', ...iconDefsultStyle, - }; + } } - if (!data.popoverShow) data.popoverShow = true; - }, 200); -}; + if (!data.popoverShow) data.popoverShow = true + }, 200) +} const close = (time) => { setTimeout(() => { - data.popoverShow = false; - data.showStyle = data.defaultStyle; - }, time || 0); -}; + data.popoverShow = false + data.showStyle = data.defaultStyle + }, time || 0) +} const handleClickOutside = (event) => { - if (data.popoverShow = false) { + if ((data.popoverShow = false)) { return false } if (bubbleRef.value && !bubbleRef.value.contains(event.target)) { - close(); + close() } -}; +} onMounted(() => { - document.addEventListener('click', handleClickOutside); - }); + document.addEventListener('click', handleClickOutside) +}) onBeforeUnmount(() => { - document.removeEventListener('click', handleClickOutside); -}); + document.removeEventListener('click', handleClickOutside) +}) diff --git a/src/uni_modules/all-speech/js_sdk/h5-speech/speech.js b/src/uni_modules/all-speech/js_sdk/h5-speech/speech.js new file mode 100644 index 0000000..e950556 --- /dev/null +++ b/src/uni_modules/all-speech/js_sdk/h5-speech/speech.js @@ -0,0 +1,226 @@ +class Recoder { + constructor(sampleRate) { + this.leftDataList = [] + this.rightDataList = [] + this.mediaPlayer = null + this.audioContext = null + this.source = null + this.sampleRate = sampleRate || 44100 + } + start() { + return new Promise((resolve, reject) => { + window.navigator.mediaDevices.getUserMedia({ + audio: { + sampleRate: 8000, // 采样率 + channelCount: 1, // 声道 + audioBitsPerSecond: 64, + volume: 1.0, // 音量 + autoGainControl: true + } + }).then(mediaStream => { + console.log(mediaStream, 'mediaStream') + this.mediaPlayer = mediaStream + this.beginRecord(mediaStream) + resolve() + }).catch(err => { + // 如果用户电脑没有麦克风设备或者用户拒绝了,或者连接出问题了等 + // 这里都会抛异常,并且通过err.name可以知道是哪种类型的错误 + console.error(err) + reject(err) + }) + }) + } + + beginRecord(mediaStream) { + let audioContext = new(window.AudioContext || window.webkitAudioContext)() + // mediaNode包含 mediaStream,audioContext + let mediaNode = audioContext.createMediaStreamSource(mediaStream) + console.log(mediaNode, 'mediaNode') + // 创建一个jsNode + // audioContext.sampleRate = 8000 + console.log(audioContext, 'audioContext') + let jsNode = this.createJSNode(audioContext) + console.log(jsNode, 'jsnode') + // 需要连到扬声器消费掉outputBuffer,process回调才能触发 + // 并且由于不给outputBuffer设置内容,所以扬声器不会播放出声音 + jsNode.connect(audioContext.destination) + jsNode.onaudioprocess = this.onAudioProcess.bind(this) + // 把mediaNode连接到jsNode + mediaNode.connect(jsNode) + this.audioContext = audioContext + } + + onAudioProcess(event) { + console.log('is recording') + // 拿到输入buffer Float32Array + let audioBuffer = event.inputBuffer + let leftChannelData = audioBuffer.getChannelData(0) + // let rightChannelData = audioBuffer.getChannelData(1) + + // 需要克隆一下 + this.leftDataList.push(leftChannelData.slice(0)) + //this.rightDataList.push(rightChannelData.slice(0)) + } + + createJSNode(audioContext) { + const BUFFER_SIZE = 4096 + const INPUT_CHANNEL_COUNT = 1 + const OUTPUT_CHANNEL_COUNT = 1 + // createJavaScriptNode已被废弃 + let creator = audioContext.createScriptProcessor || audioContext.createJavaScriptNode + creator = creator.bind(audioContext) + return creator(BUFFER_SIZE, INPUT_CHANNEL_COUNT, OUTPUT_CHANNEL_COUNT) + } + + playRecord(arrayBuffer) { + let blob = new Blob([new Int8Array(arrayBuffer)], { + type: 'audio/mp3' // files[0].type + }) + let blobUrl = URL.createObjectURL(blob) + this.source = blob + this.blobUrl = blobUrl + // document.querySelector(‘.audio-node‘).src = blobUrl + return blobUrl + } + + stop() { + // 停止录音 + let leftData = this.mergeArray(this.leftDataList) + //let rightData = this.mergeArray(this.rightDataList) + let allData = this.interSingleData(leftData) + let wavBuffer = this.createWavFile(allData) + + // 转到播放 + let source = this.playRecord(wavBuffer) + // if (source) { + // source = source.slice(5) + // } + console.log("我最后转换完播放的---------------------", source); + this.resetRecord() + return source + } + + transformArrayBufferToBase64(buffer) { + var binary = '' + var bytes = new Uint8Array(buffer) + for (var len = bytes.byteLength, i = 0; i < len; i++) { + binary += String.fromCharCode(bytes[i]) + } + return window.btoa(binary) + } + + // 停止控件录音 + resetRecord() { + this.leftDataList = [] + this.rightDataList = [] + this.audioContext.close() + this.mediaPlayer.getAudioTracks().forEach(track => { + track.stop() + this.mediaPlayer.removeTrack(track) + }) + } + + createWavFile(audioData) { + let channelCount = 1 + const WAV_HEAD_SIZE = 44 + const sampleBits = 16 + let sampleRate = this.sampleRate + + let buffer = new ArrayBuffer(audioData.length * 2 + WAV_HEAD_SIZE) + // 需要用一个view来操控buffer + let view = new DataView(buffer) + // 写入wav头部信息 + // RIFF chunk descriptor/identifier + this.writeUTFBytes(view, 0, 'RIFF') + // RIFF chunk length + view.setUint32(4, 44 + audioData.length * channelCount, true) + // RIFF type + this.writeUTFBytes(view, 8, 'WAVE') + // format chunk identifier + // FMT sub-chunk + this.writeUTFBytes(view, 12, 'fmt ') + // format chunk length + view.setUint32(16, 16, true) + // sample format (raw) + view.setUint16(20, 1, true) + // stereo (2 channels) + view.setUint16(22, channelCount, true) + // sample rate + view.setUint32(24, sampleRate, true) + // byte rate (sample rate * block align) + view.setUint32(28, sampleRate * 2, true) + // block align (channel count * bytes per sample) + view.setUint16(32, 2 * 2, true) + // bits per sample + view.setUint16(34, 16, true) + // data sub-chunk + // data chunk identifier + this.writeUTFBytes(view, 36, 'data') + // data chunk length + view.setUint32(40, audioData.length * 2, true) + + console.log(view, 'view') + let length = audioData.length + let index = 44 + let volume = 1 + for (let i = 0; i < length; i++) { + view.setInt16(index, audioData[i] * (0x7FFF * volume), true) + index += 2 + } + return buffer + } + + writeUTFBytes(view, offset, string) { + var lng = string.length + for (var i = 0; i < lng; i++) { + view.setUint8(offset + i, string.charCodeAt(i)) + } + } + + interSingleData(left) { + var t = left.length; + let sampleRate = this.audioContext.sampleRate, + outputSampleRate = this.sampleRate + sampleRate += 0.0; + outputSampleRate += 0.0; + var s = 0, + o = sampleRate / outputSampleRate, + u = Math.ceil(t * outputSampleRate / sampleRate), + a = new Float32Array(u); + for (let i = 0; i < u; i++) { + a[i] = left[Math.floor(s)]; + s += o; + } + return a; + } + + // 交叉合并左右声道的数据 + interleaveLeftAndRight(left, right) { + let totalLength = left.length + right.length + let data = new Float32Array(totalLength) + for (let i = 0; i < left.length; i++) { + let k = i * 2 + data[k] = left[i] + data[k + 1] = right[i] + } + return data + } + + mergeArray(list) { + let length = list.length * list[0].length + let data = new Float32Array(length) + let offset = 0 + for (let i = 0; i < list.length; i++) { + data.set(list[i], offset) + offset += list[i].length + } + return data + } + + + + +} + + +export default Recoder \ No newline at end of file diff --git a/src/uni_modules/all-speech/js_sdk/wa-permission/permission.js b/src/uni_modules/all-speech/js_sdk/wa-permission/permission.js new file mode 100644 index 0000000..e229ba0 --- /dev/null +++ b/src/uni_modules/all-speech/js_sdk/wa-permission/permission.js @@ -0,0 +1,272 @@ +/** + * 本模块封装了Android、iOS的应用权限判断、打开应用权限设置界面、以及位置系统服务是否开启 + */ + +var isIos +// #ifdef APP-PLUS +isIos = (plus.os.name == "iOS") +// #endif + +// 判断推送权限是否开启 +function judgeIosPermissionPush() { + var result = false; + var UIApplication = plus.ios.import("UIApplication"); + var app = UIApplication.sharedApplication(); + var enabledTypes = 0; + if (app.currentUserNotificationSettings) { + var settings = app.currentUserNotificationSettings(); + enabledTypes = settings.plusGetAttribute("types"); + console.log("enabledTypes1:" + enabledTypes); + if (enabledTypes == 0) { + console.log("推送权限没有开启"); + } else { + result = true; + console.log("已经开启推送功能!") + } + plus.ios.deleteObject(settings); + } else { + enabledTypes = app.enabledRemoteNotificationTypes(); + if (enabledTypes == 0) { + console.log("推送权限没有开启!"); + } else { + result = true; + console.log("已经开启推送功能!") + } + console.log("enabledTypes2:" + enabledTypes); + } + plus.ios.deleteObject(app); + plus.ios.deleteObject(UIApplication); + return result; +} + +// 判断定位权限是否开启 +function judgeIosPermissionLocation() { + var result = false; + var cllocationManger = plus.ios.import("CLLocationManager"); + var status = cllocationManger.authorizationStatus(); + result = (status != 2) + console.log("定位权限开启:" + result); + // 以下代码判断了手机设备的定位是否关闭,推荐另行使用方法 checkSystemEnableLocation + /* var enable = cllocationManger.locationServicesEnabled(); + var status = cllocationManger.authorizationStatus(); + console.log("enable:" + enable); + console.log("status:" + status); + if (enable && status != 2) { + result = true; + console.log("手机定位服务已开启且已授予定位权限"); + } else { + console.log("手机系统的定位没有打开或未给予定位权限"); + } */ + plus.ios.deleteObject(cllocationManger); + return result; +} + +// 判断麦克风权限是否开启 +function judgeIosPermissionRecord() { + var result = false; + var avaudiosession = plus.ios.import("AVAudioSession"); + var avaudio = avaudiosession.sharedInstance(); + var permissionStatus = avaudio.recordPermission(); + console.log("permissionStatus:" + permissionStatus); + if (permissionStatus == 1684369017 || permissionStatus == 1970168948) { + console.log("麦克风权限没有开启"); + } else { + result = true; + console.log("麦克风权限已经开启"); + } + plus.ios.deleteObject(avaudiosession); + return result; +} + +// 判断相机权限是否开启 +function judgeIosPermissionCamera() { + var result = false; + var AVCaptureDevice = plus.ios.import("AVCaptureDevice"); + var authStatus = AVCaptureDevice.authorizationStatusForMediaType('vide'); + console.log("authStatus:" + authStatus); + if (authStatus == 3) { + result = true; + console.log("相机权限已经开启"); + } else { + console.log("相机权限没有开启"); + } + plus.ios.deleteObject(AVCaptureDevice); + return result; +} + +// 判断相册权限是否开启 +function judgeIosPermissionPhotoLibrary() { + var result = false; + var PHPhotoLibrary = plus.ios.import("PHPhotoLibrary"); + var authStatus = PHPhotoLibrary.authorizationStatus(); + console.log("authStatus:" + authStatus); + if (authStatus == 3) { + result = true; + console.log("相册权限已经开启"); + } else { + console.log("相册权限没有开启"); + } + plus.ios.deleteObject(PHPhotoLibrary); + return result; +} + +// 判断通讯录权限是否开启 +function judgeIosPermissionContact() { + var result = false; + var CNContactStore = plus.ios.import("CNContactStore"); + var cnAuthStatus = CNContactStore.authorizationStatusForEntityType(0); + if (cnAuthStatus == 3) { + result = true; + console.log("通讯录权限已经开启"); + } else { + console.log("通讯录权限没有开启"); + } + plus.ios.deleteObject(CNContactStore); + return result; +} + +// 判断日历权限是否开启 +function judgeIosPermissionCalendar() { + var result = false; + var EKEventStore = plus.ios.import("EKEventStore"); + var ekAuthStatus = EKEventStore.authorizationStatusForEntityType(0); + if (ekAuthStatus == 3) { + result = true; + console.log("日历权限已经开启"); + } else { + console.log("日历权限没有开启"); + } + plus.ios.deleteObject(EKEventStore); + return result; +} + +// 判断备忘录权限是否开启 +function judgeIosPermissionMemo() { + var result = false; + var EKEventStore = plus.ios.import("EKEventStore"); + var ekAuthStatus = EKEventStore.authorizationStatusForEntityType(1); + if (ekAuthStatus == 3) { + result = true; + console.log("备忘录权限已经开启"); + } else { + console.log("备忘录权限没有开启"); + } + plus.ios.deleteObject(EKEventStore); + return result; +} + +// Android权限查询 +function requestAndroidPermission(permissionID) { + return new Promise((resolve, reject) => { + plus.android.requestPermissions( + [permissionID], // 理论上支持多个权限同时查询,但实际上本函数封装只处理了一个权限的情况。有需要的可自行扩展封装 + function(resultObj) { + var result = 0; + for (var i = 0; i < resultObj.granted.length; i++) { + var grantedPermission = resultObj.granted[i]; + console.log('已获取的权限:' + grantedPermission); + result = 1 + } + for (var i = 0; i < resultObj.deniedPresent.length; i++) { + var deniedPresentPermission = resultObj.deniedPresent[i]; + console.log('拒绝本次申请的权限:' + deniedPresentPermission); + result = 0 + } + for (var i = 0; i < resultObj.deniedAlways.length; i++) { + var deniedAlwaysPermission = resultObj.deniedAlways[i]; + console.log('永久拒绝申请的权限:' + deniedAlwaysPermission); + result = -1 + } + resolve(result); + // 若所需权限被拒绝,则打开APP设置界面,可以在APP设置界面打开相应权限 + // if (result != 1) { + // gotoAppPermissionSetting() + // } + }, + function(error) { + console.log('申请权限错误:' + error.code + " = " + error.message); + resolve({ + code: error.code, + message: error.message + }); + } + ); + }); +} + +// 使用一个方法,根据参数判断权限 +function judgeIosPermission(permissionID) { + if (permissionID == "location") { + return judgeIosPermissionLocation() + } else if (permissionID == "camera") { + return judgeIosPermissionCamera() + } else if (permissionID == "photoLibrary") { + return judgeIosPermissionPhotoLibrary() + } else if (permissionID == "record") { + return judgeIosPermissionRecord() + } else if (permissionID == "push") { + return judgeIosPermissionPush() + } else if (permissionID == "contact") { + return judgeIosPermissionContact() + } else if (permissionID == "calendar") { + return judgeIosPermissionCalendar() + } else if (permissionID == "memo") { + return judgeIosPermissionMemo() + } + return false; +} + +// 跳转到**应用**的权限页面 +function gotoAppPermissionSetting() { + if (isIos) { + var UIApplication = plus.ios.import("UIApplication"); + var application2 = UIApplication.sharedApplication(); + var NSURL2 = plus.ios.import("NSURL"); + // var setting2 = NSURL2.URLWithString("prefs:root=LOCATION_SERVICES"); + var setting2 = NSURL2.URLWithString("app-settings:"); + application2.openURL(setting2); + + plus.ios.deleteObject(setting2); + plus.ios.deleteObject(NSURL2); + plus.ios.deleteObject(application2); + } else { + // console.log(plus.device.vendor); + var Intent = plus.android.importClass("android.content.Intent"); + var Settings = plus.android.importClass("android.provider.Settings"); + var Uri = plus.android.importClass("android.net.Uri"); + var mainActivity = plus.android.runtimeMainActivity(); + var intent = new Intent(); + intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); + var uri = Uri.fromParts("package", mainActivity.getPackageName(), null); + intent.setData(uri); + mainActivity.startActivity(intent); + } +} + +// 检查系统的设备服务是否开启 +// var checkSystemEnableLocation = async function () { +function checkSystemEnableLocation() { + if (isIos) { + var result = false; + var cllocationManger = plus.ios.import("CLLocationManager"); + var result = cllocationManger.locationServicesEnabled(); + console.log("系统定位开启:" + result); + plus.ios.deleteObject(cllocationManger); + return result; + } else { + var context = plus.android.importClass("android.content.Context"); + var locationManager = plus.android.importClass("android.location.LocationManager"); + var main = plus.android.runtimeMainActivity(); + var mainSvr = main.getSystemService(context.LOCATION_SERVICE); + var result = mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER); + console.log("系统定位开启:" + result); + return result + } +} + +export default { + judgeIosPermission: judgeIosPermission, + requestAndroidPermission: requestAndroidPermission, + checkSystemEnableLocation: checkSystemEnableLocation, + gotoAppPermissionSetting: gotoAppPermissionSetting +} diff --git a/src/uni_modules/all-speech/package.json b/src/uni_modules/all-speech/package.json new file mode 100644 index 0000000..083a1aa --- /dev/null +++ b/src/uni_modules/all-speech/package.json @@ -0,0 +1,83 @@ +{ + "id": "all-speech", + "displayName": "allspeech长按录音动画组件,多端权限判断,可监听开始、结束、取消事件", + "version": "1.1.2", + "description": "H5、App、小程序兼容", + "keywords": [ + "长按", + "录音", + "动画组件" + ], + "repository": "", + "engines": { + }, + "dcloudext": { + "type": "component-vue", + "sale": { + "regular": { + "price": "0.00" + }, + "sourcecode": { + "price": "0.00" + } + }, + "contact": { + "qq": "" + }, + "declaration": { + "ads": "无", + "data": "无", + "permissions": "无" + }, + "npmurl": "" + }, + "uni_modules": { + "dependencies": [], + "encrypt": [], + "platforms": { + "cloud": { + "tcb": "y", + "aliyun": "y", + "alipay": "n" + }, + "client": { + "Vue": { + "vue2": "y", + "vue3": "y" + }, + "App": { + "app-vue": "y", + "app-nvue": "u" + }, + "H5-mobile": { + "Safari": "u", + "Android Browser": "u", + "微信浏览器(Android)": "n", + "QQ浏览器(Android)": "n" + }, + "H5-pc": { + "Chrome": "y", + "IE": "n", + "Edge": "n", + "Firefox": "y", + "Safari": "n" + }, + "小程序": { + "微信": "y", + "阿里": "u", + "百度": "u", + "字节跳动": "u", + "QQ": "u", + "钉钉": "u", + "快手": "u", + "飞书": "u", + "京东": "u" + }, + "快应用": { + "华为": "u", + "联盟": "u" + } + } + } + } +} diff --git a/src/uni_modules/all-speech/readme.md b/src/uni_modules/all-speech/readme.md new file mode 100644 index 0000000..cc795aa --- /dev/null +++ b/src/uni_modules/all-speech/readme.md @@ -0,0 +1,89 @@ +### nbVoiceRecord概述 + - 这是个基于uni-app 符合uni_modules 的插件 + - 无任何依赖、纯css动画 + - nb是NeverBug的意思 + +### 主要功能 + - 长按组件后弹出录音弹窗,松手完成录音,手指向上滑动可取消; + - 支持各种自定义,如弹窗高度、宽度、各处文字甚至声纹波形的尺寸和颜色; + - 已完成多端适配,自动根据授权情况提示完成授权、已获得授权才开始录音 + - endRecord回调事件附带录音文件 + +### 动画预览 + + - 默认样式 + +![默认样式](https://vkceyugu.cdn.bspapp.com/VKCEYUGU-613ff9e2-568b-4845-987f-93626e21bcde/84cf3c4f-f4f2-41e6-bb82-1414465a944d.gif) + + - 自定义按钮为圆形(红背景、白字)、弹窗为正方形 + +![正方形](https://vkceyugu.cdn.bspapp.com/VKCEYUGU-613ff9e2-568b-4845-987f-93626e21bcde/893bf1d6-593f-40e6-aeff-12afe4ebbc37.gif) + +### 基本用法: + +``` + + + + +``` + +### 全部支持参数 + +| 参数名 | 类型 | 默认值 | 作用 | 注意事项 | +| ----- | ----- | ------ | ------- | --- | +| recordOptions | Object | {duration:60000} | 录音配置 |各端支持情况不同,请自行查看[官方说明](https://uniapp.dcloud.net.cn/api/media/record-manager.html#getrecordermanager) | +| btnStyle | Object | 请查看源码 | 按钮样式 |对象格式 | +| btnHoverFontcolor | String | #000 | 按钮长按时文字颜色 | | +| btnHoverBgcolor | String | whitesmoke | 按钮长按时背景颜色 | | +| btnDefaultText | String | 长按开始录音 | 初始按钮文字 | | +| btnRecordingText | String | 录音中 | 录制时按钮文字 | | +| vibrate | Boolean | true | 震动反馈 | 弹窗、滑动取消时 | +| popupTitle | String | 正在录制音频 | 弹窗顶部文字 | | +| popupDefaultTips | String | 松手完成录音 | 录制时弹窗底部提示 | | +| popupCancelTips | String | 松手取消录音 | 滑动取消时弹窗底部提示 | | +| popupMaxWidth | Number | 600 | 弹窗展开后宽度 |注意这里几个单位都是rpx | +| popupMaxHeight | Number | 300 | 弹窗展开后高度 | | +| popupFixBottom | Number | 200 | 弹窗展开后距底部高度 | | +| popupBgColor | String | whitesmoke | 弹窗背景颜色 | | +| lineHeight | Number | 50 | 声波高度 | | +| lineStartColor | String | royalblue | 声波波谷时颜色色值 | 色值或者颜色名均可 | +| lineEndColor | String | indianred | 声波波峰时颜色色值 | | + +### 原作者其他插件 + + - [bwinBrand多端自适应企业官网、uniCloud云端一体【用户端】](https://ext.dcloud.net.cn/plugin?id=7821) + - [bwinBrand多端自适应企业官网、uniCloud云端一体【管理端】](https://ext.dcloud.net.cn/plugin?id=7822) + - [bwinAgent多端、多项目全民经纪人、uniCloud云端一体【经纪人端】](https://ext.dcloud.net.cn/plugin?id=8606) + - [bwinAgent多端、多项目全民经纪人、uniCloud云端一体【管理员端】](https://ext.dcloud.net.cn/plugin?id=8607) + - [必闻优学,教育培训机构模板(单校区版,纯模板)](https://ext.dcloud.net.cn/plugin?id=7709) + +### 一个有趣的社区 + + - [NeverBug.cn 弹幕式互动社区](https://neverbug.cn) + +### 原作者 + - QQ:123060128 + - Email:karma.zhao@gmail.com + - 官网:https://brand.neverbug.cn + +### 补充作者 + - QQ:27836407 + - Email:zgdabao.zhao@gmail.com diff --git a/src/uni_modules/tmui/locale/zh-Hans.json b/src/uni_modules/tmui/locale/zh-Hans.json index 092a5e2..a851331 100644 --- a/src/uni_modules/tmui/locale/zh-Hans.json +++ b/src/uni_modules/tmui/locale/zh-Hans.json @@ -159,35 +159,39 @@ "chat.msgRead.list": "消息接收人列表", "chat.settings.report": "投诉", "complaint": { - "title": "投诉举报", - "selectType": "选择投诉内容", - "selectPlaceholder": "请选择投诉类型", - "imageEvidence": "图片证据(最多9张)", - "addImage": "添加图片", - "complaintContent": "投诉内容(选填)", - "contentPlaceholder": "请详细描述投诉内容...", - "noticeTitle": "投诉须知", - "noticeone":"1、请选择正确的投诉类目。", - "noticetwo":"2、提供有效的违规证据如:图片、聊天信息等", - "noticethree":"3、详细描述违规问题详情,有助于我们的审核人员快速研判处置。", - "noticefour": "4、请勿针对同一问题重复投诉,以免造成资源浪费。", - "noticefive":"5、请勿滥用投诉,以免造成资源浪费", - "noticenoticeContent":"感谢您与我们共建安全社区环境,我们会尽快对您的投诉进行处理。同时我们希望您的投诉行为基于善意,提供准确有效的违规信息帮助我们更好的进行判断并且处理。同时我们会采取必要合理的措施保护投诉人的个人隐私信息,除法律法规规定的情形之外,在未获得用户许可的情况下,不会向第三方公开投诉人信息。如果存在滥用、重复无效投诉,我们可能会对投诉账号采取包括但不限于限制投诉频次、禁止投诉等限制", - "submit": "提交投诉", - "expand": "展开", - "collapse": "收起", - "typeOptions": { - "porn": "侵犯未成年", - "illegal": "欺诈骗钱", - "gambling": "违法违规", - "violence": "骚扰", - "selfHarm": "不良价值导向", - "other": "其他" - }, - "toast": { - "selectType": "请选择投诉类型", - "submitting": "提交中...", - "success": "投诉提交成功" - } + "title": "投诉举报", + "selectType": "选择投诉内容", + "selectPlaceholder": "请选择投诉类型", + "imageEvidence": "图片证据(最多9张)", + "addImage": "添加图片", + "complaintContent": "投诉内容(选填)", + "contentPlaceholder": "请详细描述投诉内容...", + "noticeTitle": "投诉须知", + "noticeone": "1、请选择正确的投诉类目。", + "noticetwo": "2、提供有效的违规证据如:图片、聊天信息等", + "noticethree": "3、详细描述违规问题详情,有助于我们的审核人员快速研判处置。", + "noticefour": "4、请勿针对同一问题重复投诉,以免造成资源浪费。", + "noticefive": "5、请勿滥用投诉,以免造成资源浪费", + "noticenoticeContent": "感谢您与我们共建安全社区环境,我们会尽快对您的投诉进行处理。同时我们希望您的投诉行为基于善意,提供准确有效的违规信息帮助我们更好的进行判断并且处理。同时我们会采取必要合理的措施保护投诉人的个人隐私信息,除法律法规规定的情形之外,在未获得用户许可的情况下,不会向第三方公开投诉人信息。如果存在滥用、重复无效投诉,我们可能会对投诉账号采取包括但不限于限制投诉频次、禁止投诉等限制", + "submit": "提交投诉", + "expand": "展开", + "collapse": "收起", + "typeOptions": { + "porn": "侵犯未成年", + "illegal": "欺诈骗钱", + "gambling": "违法违规", + "violence": "骚扰", + "selfHarm": "不良价值导向", + "other": "其他" + }, + "toast": { + "selectType": "请选择投诉类型", + "submitting": "提交中...", + "success": "投诉提交成功" } + }, + "release_hand_to_send": "松开发送", + "release_hand_to_cancel": "松开取消", + "hold_to": "按住", + "speak": "说话" } diff --git a/src/utils/common.js b/src/utils/common.js index dadad2b..0d2417d 100644 --- a/src/utils/common.js +++ b/src/utils/common.js @@ -213,3 +213,64 @@ export function handleSetWebviewStyle(hasTabBar) { }) } } + +// 通用运算函数 +/* + 函数,加法函数,用来得到精确的加法结果 + 说明:javascript的加法结果会有误差,在两个浮点数相加的时候会比较明显。这个函数返回较为精确的加法结果。 + 参数:arg1:第一个加数;arg2第二个加数;d要保留的小数位数(可以不传此参数,如果不传则不处理小数位数) + 调用:Calc.Add(arg1,arg2,d) + 返回值:两数相加的结果 +*/ +export function addition(arg1, arg2) { + arg1 = arg1.toString(), arg2 = arg2.toString(); + var arg1Arr = arg1.split("."), + arg2Arr = arg2.split("."), + d1 = arg1Arr.length == 2 ? arg1Arr[1] : "", + d2 = arg2Arr.length == 2 ? arg2Arr[1] : ""; + var maxLen = Math.max(d1.length, d2.length); + var m = Math.pow(10, maxLen); + var result = Number(((arg1 * m + arg2 * m) / m).toFixed(maxLen)); + var d = arguments[2]; + return typeof d === "number" ? Number((result).toFixed(d)) : result; +} + +/* + 函数:减法函数,用来得到精确的减法结果 + 说明:函数返回较为精确的减法结果。 + 参数:arg1:第一个加数;arg2第二个加数;d要保留的小数位数(可以不传此参数,如果不传则不处理小数位数) + 调用:Calc.Sub(arg1,arg2) + 返回值:两数相减的结果 +*/ + +/* + 函数:乘法函数,用来得到精确的乘法结果 + 说明:函数返回较为精确的乘法结果。 + 参数:arg1:第一个乘数;arg2第二个乘数;d要保留的小数位数(可以不传此参数,如果不传则不处理小数位数) + 调用:Calc.Mul(arg1,arg2) + 返回值:两数相乘的结果 +*/ +export function multiplication(arg1, arg2) { + var r1 = arg1.toString(), + r2 = arg2.toString(), + m, resultVal, d = arguments[2]; + m = (r1.split(".")[1] ? r1.split(".")[1].length : 0) + (r2.split(".")[1] ? r2.split(".")[1].length : 0); + resultVal = Number(r1.replace(".", "")) * Number(r2.replace(".", "")) / Math.pow(10, m); + return typeof d !== "number" ? Number(resultVal) : Number(resultVal.toFixed(parseInt(d))); +} + +/* + 函数:除法函数,用来得到精确的除法结果 + 说明:函数返回较为精确的除法结果。 + 参数:arg1:除数;arg2被除数;d要保留的小数位数(可以不传此参数,如果不传则不处理小数位数) + 调用:Calc.Div(arg1,arg2) + 返回值:arg1除于arg2的结果 +*/ +export function division(arg1, arg2) { + var r1 = arg1.toString(), + r2 = arg2.toString(), + m, resultVal, d = arguments[2]; + m = (r2.split(".")[1] ? r2.split(".")[1].length : 0) - (r1.split(".")[1] ? r1.split(".")[1].length : 0); + resultVal = Number(r1.replace(".", "")) / Number(r2.replace(".", "")) * Math.pow(10, m); + return typeof d !== "number" ? Number(resultVal) : Number(resultVal.toFixed(parseInt(d))); +}