fmode-ng 0.0.209 → 0.0.211
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm2022/lib/aigc/voice/fmode-voice.service.mjs +1 -1
- package/esm2022/lib/core/agent/chat/completion/fmode-completion.mjs +1 -1
- package/esm2022/lib/core/index.mjs +1 -1
- package/esm2022/lib/core/social/index.mjs +10 -0
- package/esm2022/lib/core/social/wxwork/wxwork.corp.mjs +10 -0
- package/esm2022/lib/core/social/wxwork/wxwork.sdk.mjs +10 -0
- package/esm2022/lib/social/index.mjs +1 -1
- package/esm2022/lib/social/wxwork/wxwork-auth.guard.mjs +10 -0
- package/esm2022/lib/user/comp-mobile-bind/comp-mobile-bind.component.mjs +10 -0
- package/esm2022/lib/user/index.mjs +1 -1
- package/fesm2022/fmode-ng.mjs +1 -1
- package/fesm2022/fmode-ng.mjs.map +1 -1
- package/lib/core/agent/chat/completion/fmode-completion.d.ts +3 -1
- package/lib/core/index.d.ts +1 -0
- package/lib/core/social/index.d.ts +3 -0
- package/lib/core/social/wxwork/wxwork.corp.d.ts +310 -0
- package/lib/core/social/wxwork/wxwork.sdk.d.ts +91 -0
- package/lib/social/index.d.ts +1 -0
- package/lib/social/wxwork/wxwork-auth.guard.d.ts +2 -0
- package/lib/user/comp-mobile-bind/comp-mobile-bind.component.d.ts +31 -0
- package/lib/user/comp-user-avatar/comp-user-avatar.component.d.ts +1 -1
- package/lib/user/index.d.ts +1 -0
- package/package.json +1 -1
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
* 保留所有权利 All Rights Reserved.
|
|
6
6
|
* /home/ryan/workspace/nova/nova-admin/dist/fmode-ng/esm2022/lib/aigc/voice/fmode-voice.service.mjs
|
|
7
7
|
*/
|
|
8
|
-
import Recorder from"recorder-core";function checkWorkletSupport(){try{return window.AudioWorkletNode&&window.AudioContext&&window.AudioContext.audioWorklet&&!/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)}catch(e){return!1}}Recorder.ConnectEnableWorklet=checkWorkletSupport();import"recorder-core/src/engine/pcm";import"recorder-core/src/engine/wav";import"recorder-core/src/extensions/waveview";import CryptoJS from"crypto-js";import{pcmtoWav}from"./lib/pcm2wav";import{convertFrameBufferToBase64,resampleBuffer}from"./lib/resample";export class FmodeVoiceService{constructor(e,t){this.platform=e,this.diagnostic=t,this.disableASR=!1,this.isRecording=!1,this.isUserFinish=!1,this.shouldReconnect=!0,this.reconnectAttempts=0,this.maxReconnectAttempts=3,this.reconnectDelay=1e3,this.recordWavBlob=null,this.recordPcmBlob=null,this.recordDuration=0,this.allRecordedBuffers=[],this.currentRecorder=null,this.btnStatus="UNDEFINED",this.connStatus="",this.resultText="",this.resultTextTemp="",this.durationStr="00:00",this.duration=0,this.recordType="pcm",this.encodingType="raw",this.APPID="50f4a46c",this.API_SECRET="NzFlNmFhZDJjMDNkZGM3NzI0Mzg2OGNm",this.API_KEY="106ddc40dfd4b9ca6d7b47c70fada749",this.requestPermission()}toggleRecord(){console.log("toggleRecord",this.btnStatus),"UNDEFINED"===this.btnStatus||"CLOSED"===this.btnStatus?this.startTalk():"CONNECTING"!==this.btnStatus&&"OPEN"!==this.btnStatus||this.finishTalk()}async startTalk(e){console.log("startTalk called"),this.resetState(),this.onBeforeStartTalk&&this.onBeforeStartTalk(),e?.preventDefault();try{await this.openWithPriviledge(),await this.startIndependentRecording(),this.isRecording=!0,this.shouldReconnect=!0,this.reconnectAttempts=0,setTimeout((()=>{this.connectWebSocket()}),100),this.startCountdown(),this.onAfterStartTalk&&this.onAfterStartTalk()}catch(e){console.error("Failed to start talk:",e),this.resetState()}}async finishTalk(){console.log("finishTalk called"),this.isUserFinish=!0,this.shouldReconnect=!1,this.onBeforeFinishTalk&&this.onBeforeFinishTalk();try{this.closeWebSocket(),await this.stopIndependentRecording(),this.isRecording=!1,this.clearTimers(),this.changeBtnStatus("CLOSED"),setTimeout((()=>{this.isUserFinish&&(this.onAfterFinishTalk&&this.onAfterFinishTalk(),this.isUserFinish=!1)}),500)}catch(e){console.error("Error finishing talk:",e)}}cancelTalk(){console.log("cancelTalk called"),this.onBeforeCancelTalk&&this.onBeforeCancelTalk(),this.isUserFinish=!1,this.shouldReconnect=!1,this.isRecording=!1,this.closeWebSocket(),this.cancelIndependentRecording(),this.resetState(),this.onAfterCancelTalk&&this.onAfterCancelTalk()}async startIndependentRecording(){return console.log("Starting independent recording"),this.allRecordedBuffers=[],this.createIndependentRecorder(),new Promise(((e,t)=>{this.currentRecorder.open((()=>{console.log("Independent recorder opened"),document.querySelector(".record-wave")&&Recorder.WaveView&&(this.waveClient=Recorder.WaveView({elem:".record-wave"})),this.currentRecorder.start(),this.onAfterRecordStart&&this.onAfterRecordStart(),e()}),((e,o)=>{console.error("Failed to open independent recorder:",e),t(new Error(e))}))}))}async stopIndependentRecording(){if(console.log("Stopping independent recording"),this.currentRecorder)return new Promise((e=>{this.currentRecorder.stop((async(t,o)=>{console.log("Independent recording stopped successfully",t,o),this.recordPcmBlob=t,this.recordWavBlob=await this.pcmBlobToWavBlob(t,44100),this.cleanupIndependentRecorder(),e()}),(t=>{console.error("独立录音停止失败:"+t),this.cleanupIndependentRecorder(),e()}))}));console.log("No independent recorder to stop")}cancelIndependentRecording(){if(console.log("Cancelling independent recording"),this.currentRecorder)try{this.currentRecorder.close()}catch(e){console.error("Error closing independent recorder:",e)}this.cleanupIndependentRecorder(),this.recordPcmBlob=null,this.recordWavBlob=null}createIndependentRecorder(){this.currentRecorder&&this.cleanupIndependentRecorder(),this.currentRecorder=Recorder({type:this.recordType,sampleRate:44100,bitRate:16,onProcess:(e,t,o,r,i,s)=>{if(!this.isRecording)return;this.allRecordedBuffers=e;let n=e.length&&e[e.length-1];n&&(n=resampleBuffer(n,44100,16e3),this.sendAudioToWebSocket(n),this.waveClient?.input(e[e.length-1],t,r))}})}cleanupIndependentRecorder(){if(this.currentRecorder){try{this.currentRecorder.close()}catch(e){console.error("Error cleaning up independent recorder:",e)}this.currentRecorder=null}}sendAudioToWebSocket(e){if(this.iatWS&&this.iatWS.readyState===WebSocket.OPEN&&!this.disableASR)try{this.iatWS.send(JSON.stringify({data:{status:1,format:"audio/L16;rate=16000",encoding:this.encodingType,audio:convertFrameBufferToBase64(e)}}))}catch(e){console.error("Error sending audio data to WebSocket:",e)}}connectWebSocket(){if(console.log("connectWebSocket called, shouldReconnect:",this.shouldReconnect),!this.shouldReconnect||!this.isRecording)return void console.log("Not connecting WebSocket - shouldReconnect:",this.shouldReconnect,"isRecording:",this.isRecording);this.closeWebSocket();const e=this.getWebSocketUrl();console.log("Connecting to:",e);try{if(!("WebSocket"in window))return console.error("浏览器不支持WebSocket"),void alert("浏览器不支持WebSocket");this.iatWS=new WebSocket(e),this.changeBtnStatus("CONNECTING"),this.iatWS.onopen=e=>{console.log("WebSocket connected for ASR"),this.reconnectAttempts=0,this.changeBtnStatus("OPEN");const t={common:{app_id:this.APPID},business:{language:"zh_cn",domain:"iat",accent:"mandarin",vad_eos:1e4,dwa:"wpgs"},data:{status:0,format:"audio/L16;rate=16000",encoding:this.encodingType}};this.iatWS.send(JSON.stringify(t))},this.iatWS.onmessage=e=>{this.renderResult(e.data)},this.iatWS.onerror=e=>{console.error("WebSocket error:",e),this.handleWebSocketError()},this.iatWS.onclose=e=>{console.log("WebSocket closed:",e.code,e.reason),this.handleWebSocketClose(e)}}catch(e){console.error("Failed to create WebSocket:",e),this.handleWebSocketError()}}handleWebSocketClose(e){if(console.log("handleWebSocketClose",{code:e.code,reason:e.reason,shouldReconnect:this.shouldReconnect,isRecording:this.isRecording,isUserFinish:this.isUserFinish}),!this.isUserFinish&&this.shouldReconnect&&this.isRecording){try{this.iatWS&&this.iatWS.readyState===WebSocket.OPEN&&this.iatWS.send(JSON.stringify({data:{status:2,format:"audio/L16;rate=16000",encoding:this.encodingType,audio:""}}))}catch(e){console.error("Error sending end frame on close:",e)}1e3===e.code||1006===e.code||1011===e.code?this.attemptReconnect():(console.error("WebSocket closed with error code:",e.code),this.handleWebSocketError())}}handleWebSocketError(){this.shouldReconnect&&this.isRecording&&this.attemptReconnect()}attemptReconnect(){this.reconnectAttempts>=this.maxReconnectAttempts?console.error("Max reconnect attempts reached"):(this.reconnectAttempts++,console.log(`Attempting WebSocket reconnect ${this.reconnectAttempts}/${this.maxReconnectAttempts}`),setTimeout((()=>{this.shouldReconnect&&this.isRecording&&!this.isUserFinish&&this.connectWebSocket()}),this.reconnectDelay*this.reconnectAttempts))}closeWebSocket(){if(this.iatWS){try{this.iatWS.readyState===WebSocket.OPEN&&this.iatWS.send(JSON.stringify({data:{status:2,format:"audio/L16;rate=16000",encoding:this.encodingType,audio:""}})),this.iatWS.readyState!==WebSocket.OPEN&&this.iatWS.readyState!==WebSocket.CONNECTING||this.iatWS.close(1e3,"User initiated close")}catch(e){console.error("Error closing WebSocket:",e)}this.iatWS=null}}resetState(){this.resultText="",this.resultTextTemp="",this.durationStr="00:00",this.duration=0,this.recordDuration=0,this.allRecordedBuffers=[],this.clearTimers()}clearTimers(){this.countdownInterval&&(clearInterval(this.countdownInterval),this.countdownInterval=null),this.durationInterval&&(clearInterval(this.durationInterval),this.durationInterval=null)}changeBtnStatus(e){switch(this.btnStatus=e,e){case"CONNECTING":this.connStatus="建立连接中";break;case"OPEN":this.connStatus=`录音中(${this.durationStr})`;break;case"CLOSING":this.connStatus="关闭连接中";break;case"CLOSED":this.connStatus="开始录音"}}startCountdown(){this.clearTimers(),this.recordDuration=0,this.duration=0,this.now=new Date,this.durationInterval=setInterval((()=>{this.isRecording&&(this.recordDuration+=100)}),100),this.countdownInterval=setInterval((()=>{this.isRecording&&this.countTimer()}),1e3)}countTimer(){this.duration++;let e=String(Math.floor(this.duration/60)).padStart(2,"0")+":"+String(this.duration%60).padStart(2,"0");this.durationStr=e,this.connStatus=`录音中(${this.durationStr})`,this.onDurationStrChange&&this.onDurationStrChange(e)}renderResult(e){try{let t=JSON.parse(e);if(t.data&&t.data.result){let e=t.data.result,o="",r=e.ws;for(let e=0;e<r.length;e++)o+=r[e].cw[0].w;e.pgs?("apd"===e.pgs&&(this.resultText=this.resultTextTemp),this.resultTextTemp=this.resultText+o):this.resultText=this.resultText+o,this.onInputChange&&this.onInputChange(this.getUserInput())}0===t.code&&2===t.data.status&&(console.log("ASR session completed, will reconnect if still recording"),this.iatWS&&this.iatWS.readyState===WebSocket.OPEN&&this.iatWS.close()),0!==t.code&&(console.error("ASR error:",t),this.iatWS&&this.iatWS.readyState===WebSocket.OPEN&&this.iatWS.close())}catch(e){console.error("Error parsing result:",e)}}getUserInput(){return""+(this.resultTextTemp||this.resultText)}async openWithPriviledge(){return await this.requestPermission(),Recorder.IsOpen(),!0}async pcmBlobToWavBlob(e,t){return new Promise((o=>{let r=new FileReader;r.onload=function(e){let r=e.target.result,i=pcmtoWav(r,t,1,16);o(i)},r.readAsArrayBuffer(e)}))}async playPCM(e,t){let o=await this.pcmBlobToWavBlob(e,t),r=window.URL.createObjectURL(o),i=new Audio;i.src=r,i.play()}playRecord(){this.recordPcmBlob&&this.playPCM(this.recordPcmBlob,44100)}getWebSocketUrl(){let e="wss://iat-api.xfyun.cn/v2/iat",t="iat-api.xfyun.cn",o=this.API_KEY,r=this.API_SECRET,i=(new Date).toUTCString(),s=`host: ${t}\ndate: ${i}\nGET /v2/iat HTTP/1.1`,n=CryptoJS.HmacSHA256(s,r),c=CryptoJS.enc.Base64.stringify(n);return e=`${e}?authorization=${btoa(`api_key="${o}", algorithm="hmac-sha256", headers="host date request-line", signature="${c}"`)}&date=${i}&host=${t}`,e}toBase64(e){for(var t="",o=new Uint8Array(e),r=o.byteLength,i=0;i<r;i++)t+=String.fromCharCode(o[i]);return window.btoa(t)}isCapacitor(){return!!this.platform?.is&&(this.platform.is("capacitor")||this.platform.is("cordova"))}async requestPermission(){if(this.isCapacitor())try{await this.requestStoagePermission(),await this.requestCameraPermission(),await this.requestMicPermission(),await this.requestRecordAudioPermission()}catch(e){console.error(e)}}async requestRecordAudioPermission(){let e=await this.diagnostic.requestRuntimePermissions([this.diagnostic.permission.RECORD_AUDIO]);console.log("record permission request:",e)}async requestMicPermission(){let e=await this.diagnostic.isMicrophoneAuthorized();if(console.log("permisson_MIC:",e),!e){await this.diagnostic.requestMicrophoneAuthorization()}}async requestStoagePermission(){let e=await this.diagnostic.isExternalStorageAuthorized();if(console.log("permisson_STORAGE:",e),!e){await this.diagnostic.requestExternalStorageAuthorization()}}async requestCameraPermission(){let e=await this.diagnostic.isCameraAuthorized();if(console.log("permisson_Camera:",e),!e){await this.diagnostic.requestCameraAuthorization()}}splitAudioData(e){const t=1280,o=Math.ceil(e.length/t),r=[];for(let i=0;i<o;i++){const o=i*t,s=o+t,n=e.slice(o,s);r.push(n)}return r}BufferToBlob(e){return new Blob([e],{type:"audio/pcm"})}async playBuffers(){let e=await this.BuffersToBlob(this.allRecordedBuffers);this.playPCM(e,44100)}BuffersToBlob(e){let t=[];return e.forEach((e=>{e.forEach((e=>{t.push(e)}))})),new Blob([t],{type:"audio/pcm"})}}
|
|
8
|
+
import Recorder from"recorder-core";function checkWorkletSupport(){try{return window.AudioWorkletNode&&window.AudioContext&&window.AudioContext?.audioWorklet&&!/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)}catch(e){return!1}}Recorder.ConnectEnableWorklet=checkWorkletSupport();import"recorder-core/src/engine/pcm";import"recorder-core/src/engine/wav";import"recorder-core/src/extensions/waveview";import CryptoJS from"crypto-js";import{pcmtoWav}from"./lib/pcm2wav";import{convertFrameBufferToBase64,resampleBuffer}from"./lib/resample";export class FmodeVoiceService{constructor(e,t){this.platform=e,this.diagnostic=t,this.disableASR=!1,this.isRecording=!1,this.isUserFinish=!1,this.shouldReconnect=!0,this.reconnectAttempts=0,this.maxReconnectAttempts=3,this.reconnectDelay=1e3,this.recordWavBlob=null,this.recordPcmBlob=null,this.recordDuration=0,this.allRecordedBuffers=[],this.currentRecorder=null,this.btnStatus="UNDEFINED",this.connStatus="",this.resultText="",this.resultTextTemp="",this.durationStr="00:00",this.duration=0,this.recordType="pcm",this.encodingType="raw",this.APPID="50f4a46c",this.API_SECRET="NzFlNmFhZDJjMDNkZGM3NzI0Mzg2OGNm",this.API_KEY="106ddc40dfd4b9ca6d7b47c70fada749",this.requestPermission()}toggleRecord(){console.log("toggleRecord",this.btnStatus),"UNDEFINED"===this.btnStatus||"CLOSED"===this.btnStatus?this.startTalk():"CONNECTING"!==this.btnStatus&&"OPEN"!==this.btnStatus||this.finishTalk()}async startTalk(e){console.log("startTalk called"),this.resetState(),this.onBeforeStartTalk&&this.onBeforeStartTalk(),e?.preventDefault();try{await this.openWithPriviledge(),await this.startIndependentRecording(),this.isRecording=!0,this.shouldReconnect=!0,this.reconnectAttempts=0,setTimeout((()=>{this.connectWebSocket()}),100),this.startCountdown(),this.onAfterStartTalk&&this.onAfterStartTalk()}catch(e){console.error("Failed to start talk:",e),this.resetState()}}async finishTalk(){console.log("finishTalk called"),this.isUserFinish=!0,this.shouldReconnect=!1,this.onBeforeFinishTalk&&this.onBeforeFinishTalk();try{this.closeWebSocket(),await this.stopIndependentRecording(),this.isRecording=!1,this.clearTimers(),this.changeBtnStatus("CLOSED"),setTimeout((()=>{this.isUserFinish&&(this.onAfterFinishTalk&&this.onAfterFinishTalk(),this.isUserFinish=!1)}),500)}catch(e){console.error("Error finishing talk:",e)}}cancelTalk(){console.log("cancelTalk called"),this.onBeforeCancelTalk&&this.onBeforeCancelTalk(),this.isUserFinish=!1,this.shouldReconnect=!1,this.isRecording=!1,this.closeWebSocket(),this.cancelIndependentRecording(),this.resetState(),this.onAfterCancelTalk&&this.onAfterCancelTalk()}async startIndependentRecording(){return console.log("Starting independent recording"),this.allRecordedBuffers=[],this.createIndependentRecorder(),new Promise(((e,t)=>{this.currentRecorder.open((()=>{console.log("Independent recorder opened"),document.querySelector(".record-wave")&&Recorder.WaveView&&(this.waveClient=Recorder.WaveView({elem:".record-wave"})),this.currentRecorder.start(),this.onAfterRecordStart&&this.onAfterRecordStart(),e()}),((e,o)=>{console.error("Failed to open independent recorder:",e),t(new Error(e))}))}))}async stopIndependentRecording(){if(console.log("Stopping independent recording"),this.currentRecorder)return new Promise((e=>{this.currentRecorder.stop((async(t,o)=>{console.log("Independent recording stopped successfully",t,o),this.recordPcmBlob=t,this.recordWavBlob=await this.pcmBlobToWavBlob(t,44100),this.cleanupIndependentRecorder(),e()}),(t=>{console.error("独立录音停止失败:"+t),this.cleanupIndependentRecorder(),e()}))}));console.log("No independent recorder to stop")}cancelIndependentRecording(){if(console.log("Cancelling independent recording"),this.currentRecorder)try{this.currentRecorder.close()}catch(e){console.error("Error closing independent recorder:",e)}this.cleanupIndependentRecorder(),this.recordPcmBlob=null,this.recordWavBlob=null}createIndependentRecorder(){this.currentRecorder&&this.cleanupIndependentRecorder(),this.currentRecorder=Recorder({type:this.recordType,sampleRate:44100,bitRate:16,onProcess:(e,t,o,r,i,s)=>{if(!this.isRecording)return;this.allRecordedBuffers=e;let n=e.length&&e[e.length-1];n&&(n=resampleBuffer(n,44100,16e3),this.sendAudioToWebSocket(n),this.waveClient?.input(e[e.length-1],t,r))}})}cleanupIndependentRecorder(){if(this.currentRecorder){try{this.currentRecorder.close()}catch(e){console.error("Error cleaning up independent recorder:",e)}this.currentRecorder=null}}sendAudioToWebSocket(e){if(this.iatWS&&this.iatWS.readyState===WebSocket.OPEN&&!this.disableASR)try{this.iatWS.send(JSON.stringify({data:{status:1,format:"audio/L16;rate=16000",encoding:this.encodingType,audio:convertFrameBufferToBase64(e)}}))}catch(e){console.error("Error sending audio data to WebSocket:",e)}}connectWebSocket(){if(console.log("connectWebSocket called, shouldReconnect:",this.shouldReconnect),!this.shouldReconnect||!this.isRecording)return void console.log("Not connecting WebSocket - shouldReconnect:",this.shouldReconnect,"isRecording:",this.isRecording);this.closeWebSocket();const e=this.getWebSocketUrl();console.log("Connecting to:",e);try{if(!("WebSocket"in window))return console.error("浏览器不支持WebSocket"),void alert("浏览器不支持WebSocket");this.iatWS=new WebSocket(e),this.changeBtnStatus("CONNECTING"),this.iatWS.onopen=e=>{console.log("WebSocket connected for ASR"),this.reconnectAttempts=0,this.changeBtnStatus("OPEN");const t={common:{app_id:this.APPID},business:{language:"zh_cn",domain:"iat",accent:"mandarin",vad_eos:1e4,dwa:"wpgs"},data:{status:0,format:"audio/L16;rate=16000",encoding:this.encodingType}};this.iatWS.send(JSON.stringify(t))},this.iatWS.onmessage=e=>{this.renderResult(e.data)},this.iatWS.onerror=e=>{console.error("WebSocket error:",e),this.handleWebSocketError()},this.iatWS.onclose=e=>{console.log("WebSocket closed:",e.code,e.reason),this.handleWebSocketClose(e)}}catch(e){console.error("Failed to create WebSocket:",e),this.handleWebSocketError()}}handleWebSocketClose(e){if(console.log("handleWebSocketClose",{code:e.code,reason:e.reason,shouldReconnect:this.shouldReconnect,isRecording:this.isRecording,isUserFinish:this.isUserFinish}),!this.isUserFinish&&this.shouldReconnect&&this.isRecording){try{this.iatWS&&this.iatWS.readyState===WebSocket.OPEN&&this.iatWS.send(JSON.stringify({data:{status:2,format:"audio/L16;rate=16000",encoding:this.encodingType,audio:""}}))}catch(e){console.error("Error sending end frame on close:",e)}1e3===e.code||1006===e.code||1011===e.code?this.attemptReconnect():(console.error("WebSocket closed with error code:",e.code),this.handleWebSocketError())}}handleWebSocketError(){this.shouldReconnect&&this.isRecording&&this.attemptReconnect()}attemptReconnect(){this.reconnectAttempts>=this.maxReconnectAttempts?console.error("Max reconnect attempts reached"):(this.reconnectAttempts++,console.log(`Attempting WebSocket reconnect ${this.reconnectAttempts}/${this.maxReconnectAttempts}`),setTimeout((()=>{this.shouldReconnect&&this.isRecording&&!this.isUserFinish&&this.connectWebSocket()}),this.reconnectDelay*this.reconnectAttempts))}closeWebSocket(){if(this.iatWS){try{this.iatWS.readyState===WebSocket.OPEN&&this.iatWS.send(JSON.stringify({data:{status:2,format:"audio/L16;rate=16000",encoding:this.encodingType,audio:""}})),this.iatWS.readyState!==WebSocket.OPEN&&this.iatWS.readyState!==WebSocket.CONNECTING||this.iatWS.close(1e3,"User initiated close")}catch(e){console.error("Error closing WebSocket:",e)}this.iatWS=null}}resetState(){this.resultText="",this.resultTextTemp="",this.durationStr="00:00",this.duration=0,this.recordDuration=0,this.allRecordedBuffers=[],this.clearTimers()}clearTimers(){this.countdownInterval&&(clearInterval(this.countdownInterval),this.countdownInterval=null),this.durationInterval&&(clearInterval(this.durationInterval),this.durationInterval=null)}changeBtnStatus(e){switch(this.btnStatus=e,e){case"CONNECTING":this.connStatus="建立连接中";break;case"OPEN":this.connStatus=`录音中(${this.durationStr})`;break;case"CLOSING":this.connStatus="关闭连接中";break;case"CLOSED":this.connStatus="开始录音"}}startCountdown(){this.clearTimers(),this.recordDuration=0,this.duration=0,this.now=new Date,this.durationInterval=setInterval((()=>{this.isRecording&&(this.recordDuration+=100)}),100),this.countdownInterval=setInterval((()=>{this.isRecording&&this.countTimer()}),1e3)}countTimer(){this.duration++;let e=String(Math.floor(this.duration/60)).padStart(2,"0")+":"+String(this.duration%60).padStart(2,"0");this.durationStr=e,this.connStatus=`录音中(${this.durationStr})`,this.onDurationStrChange&&this.onDurationStrChange(e)}renderResult(e){try{let t=JSON.parse(e);if(t.data&&t.data.result){let e=t.data.result,o="",r=e.ws;for(let e=0;e<r.length;e++)o+=r[e].cw[0].w;e.pgs?("apd"===e.pgs&&(this.resultText=this.resultTextTemp),this.resultTextTemp=this.resultText+o):this.resultText=this.resultText+o,this.onInputChange&&this.onInputChange(this.getUserInput())}0===t.code&&2===t.data.status&&(console.log("ASR session completed, will reconnect if still recording"),this.iatWS&&this.iatWS.readyState===WebSocket.OPEN&&this.iatWS.close()),0!==t.code&&(console.error("ASR error:",t),this.iatWS&&this.iatWS.readyState===WebSocket.OPEN&&this.iatWS.close())}catch(e){console.error("Error parsing result:",e)}}getUserInput(){return""+(this.resultTextTemp||this.resultText)}async openWithPriviledge(){return await this.requestPermission(),Recorder.IsOpen(),!0}async pcmBlobToWavBlob(e,t){return new Promise((o=>{let r=new FileReader;r.onload=function(e){let r=e.target.result,i=pcmtoWav(r,t,1,16);o(i)},r.readAsArrayBuffer(e)}))}async playPCM(e,t){let o=await this.pcmBlobToWavBlob(e,t),r=window.URL.createObjectURL(o),i=new Audio;i.src=r,i.play()}playRecord(){this.recordPcmBlob&&this.playPCM(this.recordPcmBlob,44100)}getWebSocketUrl(){let e="wss://iat-api.xfyun.cn/v2/iat",t="iat-api.xfyun.cn",o=this.API_KEY,r=this.API_SECRET,i=(new Date).toUTCString(),s=`host: ${t}\ndate: ${i}\nGET /v2/iat HTTP/1.1`,n=CryptoJS.HmacSHA256(s,r),c=CryptoJS.enc.Base64.stringify(n);return e=`${e}?authorization=${btoa(`api_key="${o}", algorithm="hmac-sha256", headers="host date request-line", signature="${c}"`)}&date=${i}&host=${t}`,e}toBase64(e){for(var t="",o=new Uint8Array(e),r=o.byteLength,i=0;i<r;i++)t+=String.fromCharCode(o[i]);return window.btoa(t)}isCapacitor(){return!!this.platform?.is&&(this.platform.is("capacitor")||this.platform.is("cordova"))}async requestPermission(){if(this.isCapacitor())try{await this.requestStoagePermission(),await this.requestCameraPermission(),await this.requestMicPermission(),await this.requestRecordAudioPermission()}catch(e){console.error(e)}}async requestRecordAudioPermission(){let e=await this.diagnostic.requestRuntimePermissions([this.diagnostic.permission.RECORD_AUDIO]);console.log("record permission request:",e)}async requestMicPermission(){let e=await this.diagnostic.isMicrophoneAuthorized();if(console.log("permisson_MIC:",e),!e){await this.diagnostic.requestMicrophoneAuthorization()}}async requestStoagePermission(){let e=await this.diagnostic.isExternalStorageAuthorized();if(console.log("permisson_STORAGE:",e),!e){await this.diagnostic.requestExternalStorageAuthorization()}}async requestCameraPermission(){let e=await this.diagnostic.isCameraAuthorized();if(console.log("permisson_Camera:",e),!e){await this.diagnostic.requestCameraAuthorization()}}splitAudioData(e){const t=1280,o=Math.ceil(e.length/t),r=[];for(let i=0;i<o;i++){const o=i*t,s=o+t,n=e.slice(o,s);r.push(n)}return r}BufferToBlob(e){return new Blob([e],{type:"audio/pcm"})}async playBuffers(){let e=await this.BuffersToBlob(this.allRecordedBuffers);this.playPCM(e,44100)}BuffersToBlob(e){let t=[];return e.forEach((e=>{e.forEach((e=>{t.push(e)}))})),new Blob([t],{type:"audio/pcm"})}}
|
|
9
9
|
var MODULE_PATH_NEED = `6K+l5paH5Lu25piv5pys6aG555uu55qE5LiA6YOo5YiGIFRoaXMgZmlsZSBpcyBwYXJ0IG9mIHRoZSBDb21wb25lbnRzIGluIEZtb2RlIEluYy4KICAgIOeJiOadg+aJgOaciSDCqSDmnKrmnaXpo57pqawgwqkg5rGf6KW/6ISR5o6n56eR5oqA5pyJ6ZmQ5YWs5Y+4IENvcHlyaWdodCDCqSBGbW9kZSBUZWNobm9sb2d5IENvLiwgTHRkLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCBSaWdodHMgUmVzZXJ2ZWQuCiAgICDkuKXnpoHlnKjmnKrnu4/mjojmnYPnmoTmg4XlhrXkuIvvvIzpgJrov4fku7vkvZXlqpLku4vlpI3liLbmraTmlofku7YgVW5hdXRob3JpemVkIGNvcHlpbmcgb2YgdGhpcyBmaWxlLCB2aWEgYW55IG1lZGl1bSBpcyBzdHJpY3RseSBwcm9oaWJpdGVkCiAgICDor6Xmlofku7bmmK/kuJPmnInnmoTmnLrlr4bmlofku7YgUHJvcHJpZXRhcnkgYW5kIGNvbmZpZGVudGlhbAogICAKICAgIENvcHlyaWdodCAyMDIxLW5vdyBGbW9kZSBJbmMuIHN1cHBvcnRAZm1vZGUuY24uIDE4NjA3MDA3MDczLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCByaWdodHMgcmVzZXJ2ZWQuCgogICAgUEFUSDovaG9tZS9yeWFuL3dvcmtzcGFjZS9ub3ZhL25vdmEtYWRtaW4vZGlzdC9mbW9kZS1uZy9lc20yMDIyL2xpYi9haWdjL3ZvaWNlL2Ztb2RlLXZvaWNlLnNlcnZpY2UubWpz`
|
|
10
10
|
|
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
* 保留所有权利 All Rights Reserved.
|
|
6
6
|
* /home/ryan/workspace/nova/nova-admin/dist/fmode-ng/esm2022/lib/core/agent/chat/completion/fmode-completion.mjs
|
|
7
7
|
*/
|
|
8
|
-
import{bufferTime,concatMap,delay,Observable}from"rxjs";const API_BASE="https://server.fmode.cn/api/apig/aigc/gpt";import{FmodeParse}from"../../../../core/parse";const Parse=FmodeParse.with("nova");export class FmodeChatCompletion{constructor(e,t){this.content="",this.contentBuffer=[],this.isCompleted=!1,this.indexOfList=Number(e.length),this.messages=e,this.model=t?.model||"fmode-1.6-cn",this.max_tokens=t?.max_tokens||32768}sendCompletion(e={messages:[]}){e.intTime=e?.intTime||50,e.isDirect=e?.isDirect||!1,e?.isDirect&&(e.intTime=1);
|
|
8
|
+
import{bufferTime,concatMap,delay,Observable}from"rxjs";const API_BASE="https://server.fmode.cn/api/apig/aigc/gpt";import{FmodeParse}from"../../../../core/parse";const Parse=FmodeParse.with("nova");export class FmodeChatCompletion{constructor(e,t){this.content="",this.contentBuffer=[],this.isCompleted=!1,this.indexOfList=Number(e.length),this.messages=e,this.model=t?.model||"fmode-1.6-cn",this.max_tokens=t?.max_tokens||32768}sendCompletion(e={messages:[]}){e.intTime=e?.intTime||50,e.isDirect=e?.isDirect||!1,e?.isDirect&&(e.intTime=1);const t={messages:this.messages,stream:!0,model:this.model,temperature:e?.temperature||.5,presence_penalty:e?.presence_penalty||0,frequency_penalty:e?.frequency_penalty||0};return this.model.indexOf("1.6")>-1&&(t.thinking=t.thinking||{type:"disabled"}),e?.max_tokens&&(t.max_tokens=e?.max_tokens||this.max_tokens),new Observable((n=>{let r=RequestFmodeChatApi("/v1/chat/completions",t).subscribe((t=>{let o,s=String(t);try{o=chunkToJson(s)}catch(e){}if(("data: [DONE]"==s||o?.created&&o?.choices?.[0]?.finish_reason)&&(this.isCompleted=!0,e?.isDirect&&this.isCompleted&&(n.next({role:"assistant",content:this.content,complete:!0,createdAt:new Date}),r.unsubscribe(),e?.onComplete&&e.onComplete({role:"assistant",content:this.content,complete:!0,createdAt:new Date}),n.complete())),s.indexOf("data: {")>-1){let t=o?.choices?.[0]?.delta?.content||"";this.contentBuffer.push(t),e?.isDirect&&(this.content+=t||"",this.isCompleted||n.next({role:"assistant",cid:o?.id,content:this.content,createdAt:new Date})),e?.isDirect||this.contentPusher||(this.contentPusher=setInterval((()=>{this.isCompleted&&0==this.contentBuffer?.length&&(n.next({role:"assistant",cid:o?.id,content:this.content,complete:!0,createdAt:new Date}),r.unsubscribe(),clearInterval(this.contentPusher),n.complete()),this.contentBuffer?.length>=0&&(this.contentBuffer?.length>0&&(this.content+=this.contentBuffer.shift()),n.next({role:"assistant",cid:o?.id,content:this.content,createdAt:new Date}))}),e?.intTime))}}))})).pipe(bufferTime(100),concatMap((e=>e)),delay(200))}}function chunkToJson(e){let t;try{t=JSON.parse(e.replaceAll("data: ",""))}catch(e){}return t||{}}function RequestFmodeChatApi(e,t,n="POST"){return new Observable((r=>{let o=API_BASE+e,s=`Bearer ${Parse.User.current()?.getSessionToken()||localStorage.getItem("FMODE_AI_TOKEN")}`;return t.token=s,t&&(t=JSON.stringify(t)),fetch(o,{headers:{"Content-Type":"text/plain; charset=utf-8","Cache-Control":"no-cache"},body:t||null,method:n,credentials:"omit",mode:"cors"}).then((e=>{let t="";{const n=e.body?.getReader();if(!n)return void r.error(new Error("Response body reader is null"));const o=new TextDecoder;let s=new ReadableStream({start(e){!function read(){try{e&&n.read().then((({done:t,value:n})=>{if(t)return e?.close(),void r.complete();e?.enqueue(n),read()})).catch((e=>{}))}catch(e){console.log("err2",e)}}()}}).getReader();s.read().then((function processStream(e){let{done:n,value:a}=e;n||(!function processData(e){let n=(t+e).split("\n");if(n?.length>1){for(let e=0;e<n.length-1;e++){let t=n[e];r.next(t)}t=n[n.length-1]}}(o.decode(a)),s.read().then(processStream))}))}})).catch((e=>r.error(e))),()=>{}}))}function JsonToFormData(e){const t=new FormData;return function appendFormData(e,n=""){Array.isArray(e)?e.forEach(((e,t)=>{appendFormData(e,`${n}[${t}]`)})):"object"==typeof e&&null!==e?Object.keys(e).forEach((t=>{const r=n?`${n}.${t}`:t;appendFormData(e[t],r)})):t.append(n,e)}(e),t}export async function completionJSON(e,t,n,r=1,o){o=o||{};let s=0;const attemptCompletion=async()=>{const r=`请严格按照以下要求生成JSON数据:\n- 数据结构要求:${t}\n- 返回一个完整的JSON对象,请确保JSON格式完整,不要遗漏任何标点符号\n- 注意返回的JSON格式每个KEY都有""包裹和Value之间都有:\n- 注意""字符串内再出现"符号需要用\\"转义\n`;let a;if(Array.isArray(e))a=e;else if(o.vision&&o.images&&o.images.length>0){a=[{role:"user",content:[...o.images.map((e=>({type:"image_url",image_url:{url:e}}))),{type:"text",text:e+r}]}]}else a=[{role:"user",content:e+r}];o.response_format={type:"json_object"};const c=new FmodeChatCompletion(a,o);let i="";return new Promise(((e,t)=>{const r=c.sendCompletion({isDirect:!0,max_tokens:32768}).subscribe({next:o=>{if("string"==typeof o?.content&&(i=o.content,n&&n(i)),o.complete){try{const t=extractJSON(i);if(!t)throw new Error("未能从响应中提取有效的JSON对象");e(t)}catch(e){console.error(`JSON解析失败 (第${s+1}次尝试):`,e),t(new Error(`生成的响应不符合JSON格式: ${e.message}`))}r.unsubscribe()}},error:e=>{console.error("Completion请求失败:",e),r.unsubscribe(),t(e)}})}))};for(;s<=r;)try{const e=await attemptCompletion();return s>0&&console.log(`JSON生成成功,重试了 ${s} 次`),e}catch(e){if(s++,!(s<=r))throw console.error(`JSON生成失败,已重试 ${r} 次,最终错误:`,e),new Error(`经过 ${r} 次重试后仍无法生成有效JSON: ${e.message}`);console.warn(`第 ${s} 次尝试失败,正在重试... 错误信息:`,e.message),await new Promise((e=>setTimeout(e,1e3)))}}export function extractJSON(e){try{return JSON.parse(e.trim())}catch(e){}let t=0,n=-1,r=null;for(let o=0;o<e.length;o++)if("{"===e[o])0===t&&(n=o),t++;else if("}"===e[o]&&(t--,0===t&&-1!==n))try{const t=e.slice(n,o+1);r=JSON.parse(t);break}catch(e){n=-1}return r||(r=tryFixAndParseJSON(e)),r}function tryFixAndParseJSON(e){const t=e.match(/\{[\s\S]*\}/);if(!t)return null;let n=t[0];const r=[e=>e.replace(/,(\s*[}\]])/g,"$1"),e=>e.replace(/([{,]\s*)([a-zA-Z_$][a-zA-Z0-9_$]*)\s*:/g,'$1"$2":'),e=>e.replace(/'/g,'"'),e=>e.replace(/\/\*[\s\S]*?\*\//g,"").replace(/\/\/.*$/gm,"")];for(const e of r)try{const t=e(n);return JSON.parse(t)}catch(e){}return null}
|
|
9
9
|
var MODULE_PATH_NEED = `6K+l5paH5Lu25piv5pys6aG555uu55qE5LiA6YOo5YiGIFRoaXMgZmlsZSBpcyBwYXJ0IG9mIHRoZSBDb21wb25lbnRzIGluIEZtb2RlIEluYy4KICAgIOeJiOadg+aJgOaciSDCqSDmnKrmnaXpo57pqawgwqkg5rGf6KW/6ISR5o6n56eR5oqA5pyJ6ZmQ5YWs5Y+4IENvcHlyaWdodCDCqSBGbW9kZSBUZWNobm9sb2d5IENvLiwgTHRkLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCBSaWdodHMgUmVzZXJ2ZWQuCiAgICDkuKXnpoHlnKjmnKrnu4/mjojmnYPnmoTmg4XlhrXkuIvvvIzpgJrov4fku7vkvZXlqpLku4vlpI3liLbmraTmlofku7YgVW5hdXRob3JpemVkIGNvcHlpbmcgb2YgdGhpcyBmaWxlLCB2aWEgYW55IG1lZGl1bSBpcyBzdHJpY3RseSBwcm9oaWJpdGVkCiAgICDor6Xmlofku7bmmK/kuJPmnInnmoTmnLrlr4bmlofku7YgUHJvcHJpZXRhcnkgYW5kIGNvbmZpZGVudGlhbAogICAKICAgIENvcHlyaWdodCAyMDIxLW5vdyBGbW9kZSBJbmMuIHN1cHBvcnRAZm1vZGUuY24uIDE4NjA3MDA3MDczLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCByaWdodHMgcmVzZXJ2ZWQuCgogICAgUEFUSDovaG9tZS9yeWFuL3dvcmtzcGFjZS9ub3ZhL25vdmEtYWRtaW4vZGlzdC9mbW9kZS1uZy9lc20yMDIyL2xpYi9jb3JlL2FnZW50L2NoYXQvY29tcGxldGlvbi9mbW9kZS1jb21wbGV0aW9uLm1qcw==`
|
|
10
10
|
|
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
* 保留所有权利 All Rights Reserved.
|
|
6
6
|
* /home/ryan/workspace/nova/nova-admin/dist/fmode-ng/esm2022/lib/core/index.mjs
|
|
7
7
|
*/
|
|
8
|
-
export*from"./agent";export*from"./voice";export*from"./parse";
|
|
8
|
+
export*from"./agent";export*from"./voice";export*from"./parse";export*from"./social";
|
|
9
9
|
var MODULE_PATH_NEED = `6K+l5paH5Lu25piv5pys6aG555uu55qE5LiA6YOo5YiGIFRoaXMgZmlsZSBpcyBwYXJ0IG9mIHRoZSBDb21wb25lbnRzIGluIEZtb2RlIEluYy4KICAgIOeJiOadg+aJgOaciSDCqSDmnKrmnaXpo57pqawgwqkg5rGf6KW/6ISR5o6n56eR5oqA5pyJ6ZmQ5YWs5Y+4IENvcHlyaWdodCDCqSBGbW9kZSBUZWNobm9sb2d5IENvLiwgTHRkLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCBSaWdodHMgUmVzZXJ2ZWQuCiAgICDkuKXnpoHlnKjmnKrnu4/mjojmnYPnmoTmg4XlhrXkuIvvvIzpgJrov4fku7vkvZXlqpLku4vlpI3liLbmraTmlofku7YgVW5hdXRob3JpemVkIGNvcHlpbmcgb2YgdGhpcyBmaWxlLCB2aWEgYW55IG1lZGl1bSBpcyBzdHJpY3RseSBwcm9oaWJpdGVkCiAgICDor6Xmlofku7bmmK/kuJPmnInnmoTmnLrlr4bmlofku7YgUHJvcHJpZXRhcnkgYW5kIGNvbmZpZGVudGlhbAogICAKICAgIENvcHlyaWdodCAyMDIxLW5vdyBGbW9kZSBJbmMuIHN1cHBvcnRAZm1vZGUuY24uIDE4NjA3MDA3MDczLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCByaWdodHMgcmVzZXJ2ZWQuCgogICAgUEFUSDovaG9tZS9yeWFuL3dvcmtzcGFjZS9ub3ZhL25vdmEtYWRtaW4vZGlzdC9mbW9kZS1uZy9lc20yMDIyL2xpYi9jb3JlL2luZGV4Lm1qcw==`
|
|
10
10
|
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @copyright © 未来飞马 © 未来全栈 www.fmode.cn
|
|
4
|
+
* 版权所有 © 未来飞马 © 江西脑控科技有限公司 Copyright © Fmode Technology Co., Ltd.
|
|
5
|
+
* 保留所有权利 All Rights Reserved.
|
|
6
|
+
* /home/ryan/workspace/nova/nova-admin/dist/fmode-ng/esm2022/lib/core/social/index.mjs
|
|
7
|
+
*/
|
|
8
|
+
export*from"../../social/wxwork/wxwork-auth.guard";export*from"./wxwork/wxwork.corp";export*from"./wxwork/wxwork.sdk";
|
|
9
|
+
var MODULE_PATH_NEED = `6K+l5paH5Lu25piv5pys6aG555uu55qE5LiA6YOo5YiGIFRoaXMgZmlsZSBpcyBwYXJ0IG9mIHRoZSBDb21wb25lbnRzIGluIEZtb2RlIEluYy4KICAgIOeJiOadg+aJgOaciSDCqSDmnKrmnaXpo57pqawgwqkg5rGf6KW/6ISR5o6n56eR5oqA5pyJ6ZmQ5YWs5Y+4IENvcHlyaWdodCDCqSBGbW9kZSBUZWNobm9sb2d5IENvLiwgTHRkLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCBSaWdodHMgUmVzZXJ2ZWQuCiAgICDkuKXnpoHlnKjmnKrnu4/mjojmnYPnmoTmg4XlhrXkuIvvvIzpgJrov4fku7vkvZXlqpLku4vlpI3liLbmraTmlofku7YgVW5hdXRob3JpemVkIGNvcHlpbmcgb2YgdGhpcyBmaWxlLCB2aWEgYW55IG1lZGl1bSBpcyBzdHJpY3RseSBwcm9oaWJpdGVkCiAgICDor6Xmlofku7bmmK/kuJPmnInnmoTmnLrlr4bmlofku7YgUHJvcHJpZXRhcnkgYW5kIGNvbmZpZGVudGlhbAogICAKICAgIENvcHlyaWdodCAyMDIxLW5vdyBGbW9kZSBJbmMuIHN1cHBvcnRAZm1vZGUuY24uIDE4NjA3MDA3MDczLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCByaWdodHMgcmVzZXJ2ZWQuCgogICAgUEFUSDovaG9tZS9yeWFuL3dvcmtzcGFjZS9ub3ZhL25vdmEtYWRtaW4vZGlzdC9mbW9kZS1uZy9lc20yMDIyL2xpYi9jb3JlL3NvY2lhbC9pbmRleC5tanM=`
|
|
10
|
+
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @copyright © 未来飞马 © 未来全栈 www.fmode.cn
|
|
4
|
+
* 版权所有 © 未来飞马 © 江西脑控科技有限公司 Copyright © Fmode Technology Co., Ltd.
|
|
5
|
+
* 保留所有权利 All Rights Reserved.
|
|
6
|
+
* /home/ryan/workspace/nova/nova-admin/dist/fmode-ng/esm2022/lib/core/social/wxwork/wxwork.corp.mjs
|
|
7
|
+
*/
|
|
8
|
+
export class WxworkCorp{constructor(t){this.config={},this.ticket={get:async(t="agent_config")=>{let e={};t&&(e.type=t);let a=await WwRequest({company:this.company,path:"ticket/get",method:"GET",queryParams:e});return a?.ticket}},this.service={async corpIdToOpenCorpId(t){return await WwRequest({company:this.company,path:"auth/getuserinfo",method:"GET",body:{corpid:t}})}},this.auth={getuserinfo:async t=>{let e=await WwRequest({company:this.company,path:"auth/getuserinfo",method:"GET",queryParams:{code:t}});if(console.log(e),e?.user_ticket){let t=await WwRequest({company:this.company,path:"auth/getuserdetail",method:"POST",body:{user_ticket:e?.user_ticket}});t?.qr_code&&Object.keys(t).forEach((a=>{e[a]=t[a]})),console.log("企业用户详情:",e)}return e?.openid,e||null}},this.user={getUserId:async t=>{let e=await WwRequest({company:this.company,path:"user/getuserid",method:"POST",body:{mobile:t}});return console.log(e),e?.userid||null},get:async t=>{let e=await WwRequest({company:this.company,path:"user/get",method:"GET",queryParams:{id:t}});return console.log(e),e?.department||null},listId:async(t,e,a)=>{let s="user/list_id",n="POST",o={limit:100};(t=t||null)&&(s="user/simplelist",n="GET",o=null);let i=await WwRequest({company:this.company,method:n,queryParams:{department_id:t},path:s,body:o});return console.log(i),t?i?.userlist||[]:i?.dept_user||[]},list:async t=>{let e=t?.id,a=await WwRequest({company:this.company,path:"department/list",method:"GET",queryParams:{id:e}});return console.log(a),a}},this.department={get:async t=>{let e=await WwRequest({company:this.company,path:"department/get",method:"GET",queryParams:{id:t}});return console.log(e),e?.department||null},listId:async t=>{let e=t?.id,a=await WwRequest({company:this.company,method:"GET",queryParams:{id:e},path:"department/simplelist"});return console.log(a),a?.department_id||[]},list:async t=>{let e=t?.id,a=await WwRequest({company:this.company,path:"department/list",method:"GET",queryParams:{id:e}});return console.log(a),a}},this.externalContact={get:async t=>await WwRequest({method:"GET",company:this.company,path:"externalcontact/get",queryParams:{external_userid:t}}),groupChat:{addJoinWay:async t=>await WwRequest({method:"POST",company:this.company,path:"externalcontact/groupchat/add_join_way",body:t}),getJoinWay:async t=>{if(!t)return null;return await WwRequest({method:"POST",company:this.company,path:"externalcontact/groupchat/get_join_way",body:{config_id:t}})},get:async t=>await WwRequest({method:"POST",company:this.company,path:"externalcontact/groupchat/get",body:{chat_id:t,need_name:1}}),list:async t=>{let e={limit:t?.limit||20};t?.userid_list&&(e.owner_filter={userid_list:[t?.userid_list]});let a=await WwRequest({company:this.company,path:"externalcontact/groupchat/list",body:e});return console.log(a),a}}},this.appchat={sendText:async(t,e,a=0)=>await WwRequest({company:this.company,path:"appchat/send",method:"POST",body:{chatid:t,msgtype:"text",text:{content:e},safe:a}}),sendImage:async(t,e,a=0)=>await WwRequest({company:this.company,path:"appchat/send",method:"POST",body:{chatid:t,msgtype:"image",image:{media_id:e},safe:a}}),sendVideo:async(t,e,a,s,n=0)=>await WwRequest({company:this.company,path:"appchat/send",method:"POST",body:{chatid:t,msgtype:"video",video:{media_id:e,title:a,description:s},safe:n}}),sendFile:async(t,e,a=0)=>await WwRequest({company:this.company,path:"appchat/send",method:"POST",body:{chatid:t,msgtype:"file",file:{media_id:e},safe:a}}),sendTextCard:async(t,e,a,s,n,o=0)=>await WwRequest({company:this.company,path:"appchat/send",method:"POST",body:{chatid:t,msgtype:"textcard",textcard:{title:e,description:a,url:s,btntxt:n||"详情"},safe:o}}),sendNews:async(t,e,a=0)=>await WwRequest({company:this.company,path:"appchat/send",method:"POST",body:{chatid:t,msgtype:"news",news:{articles:e},safe:a}}),sendMarkdown:async(t,e)=>await WwRequest({company:this.company,path:"appchat/send",method:"POST",body:{chatid:t,msgtype:"markdown",markdown:{content:e}}}),send:async t=>await WwRequest({company:this.company,path:"appchat/send",method:"POST",body:t})},this.meeting={create:async t=>await WwRequest({company:this.company,path:"meeting/create",method:"POST",body:t}),list:async t=>{let e={limit:t?.limit||20};return t?.userid&&(e.userid=t.userid),t?.cursor&&(e.cursor=t.cursor),t?.begin_time&&(e.begin_time=t.begin_time),t?.end_time&&(e.end_time=t.end_time),await WwRequest({company:this.company,path:"meeting/list",method:"POST",body:e})},get:async t=>await WwRequest({company:this.company,path:"meeting/get",method:"POST",body:{meetingid:t}})},this.company=t}}export async function WwRequest(t){let e,a,s=t?.company,n=t?.path,o=t?.method||"POST",i="https://server.fmode.cn/api/wework/func";t?.body&&Object.keys(t?.body)?.length&&(e=t?.body),t?.queryParams&&(a=t?.queryParams),e||(e={});let c=JSON.stringify({company:s,path:n,body:e,queryParams:a,method:o});console.log(c);let d={method:"POST",headers:{"Content-Type":"application/json"},body:c};console.log(d,i);let p=await fetch(i,d);return await p.json()}
|
|
9
|
+
var MODULE_PATH_NEED = `6K+l5paH5Lu25piv5pys6aG555uu55qE5LiA6YOo5YiGIFRoaXMgZmlsZSBpcyBwYXJ0IG9mIHRoZSBDb21wb25lbnRzIGluIEZtb2RlIEluYy4KICAgIOeJiOadg+aJgOaciSDCqSDmnKrmnaXpo57pqawgwqkg5rGf6KW/6ISR5o6n56eR5oqA5pyJ6ZmQ5YWs5Y+4IENvcHlyaWdodCDCqSBGbW9kZSBUZWNobm9sb2d5IENvLiwgTHRkLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCBSaWdodHMgUmVzZXJ2ZWQuCiAgICDkuKXnpoHlnKjmnKrnu4/mjojmnYPnmoTmg4XlhrXkuIvvvIzpgJrov4fku7vkvZXlqpLku4vlpI3liLbmraTmlofku7YgVW5hdXRob3JpemVkIGNvcHlpbmcgb2YgdGhpcyBmaWxlLCB2aWEgYW55IG1lZGl1bSBpcyBzdHJpY3RseSBwcm9oaWJpdGVkCiAgICDor6Xmlofku7bmmK/kuJPmnInnmoTmnLrlr4bmlofku7YgUHJvcHJpZXRhcnkgYW5kIGNvbmZpZGVudGlhbAogICAKICAgIENvcHlyaWdodCAyMDIxLW5vdyBGbW9kZSBJbmMuIHN1cHBvcnRAZm1vZGUuY24uIDE4NjA3MDA3MDczLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCByaWdodHMgcmVzZXJ2ZWQuCgogICAgUEFUSDovaG9tZS9yeWFuL3dvcmtzcGFjZS9ub3ZhL25vdmEtYWRtaW4vZGlzdC9mbW9kZS1uZy9lc20yMDIyL2xpYi9jb3JlL3NvY2lhbC93eHdvcmsvd3h3b3JrLmNvcnAubWpz`
|
|
10
|
+
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @copyright © 未来飞马 © 未来全栈 www.fmode.cn
|
|
4
|
+
* 版权所有 © 未来飞马 © 江西脑控科技有限公司 Copyright © Fmode Technology Co., Ltd.
|
|
5
|
+
* 保留所有权利 All Rights Reserved.
|
|
6
|
+
* /home/ryan/workspace/nova/nova-admin/dist/fmode-ng/esm2022/lib/core/social/wxwork/wxwork.sdk.mjs
|
|
7
|
+
*/
|
|
8
|
+
import*as ww from"@wecom/jssdk";import{FmodeParse}from"../../parse";const Parse=FmodeParse.with("nova");import{WxworkCorp}from"./wxwork.corp";export class WxworkSDK{constructor(e){this.companyMap={E4KpGvTEto:{corpResId:"vsVIWbd1i9"},uRiDGwEYLi:{corpResId:"JxfFXBr0ly"}},this.suiteMap={crm:{suiteId:"dk2559ba758f33d8f5"}},this.ww=ww,this.groupChat={createGroupChat:async e=>{try{return alert("createGroupChat"+JSON.stringify(e)),await this.registerCorpWithSuite()?new Promise(((t,r)=>{e.success=e=>{alert(JSON.stringify(e)),t(e)},e.fail=e=>{alert(JSON.stringify(e)),r(e)},ww.createCorpGroupChat(e)})):null}catch(e){alert(JSON.stringify(e))}},addUserInfoGroup:async e=>{alert("addUserInfoGroup"+JSON.stringify(e));try{let t=await this.registerCorpWithSuite();return alert("isRegister"+t),t?(alert(JSON.stringify(e)),new Promise(((t,r)=>{e.success=e=>{alert(JSON.stringify(e)),t(e)},e.fail=e=>{alert(JSON.stringify(e)),r(e)},ww.updateCorpGroupChat(e)}))):null}catch(e){alert(JSON.stringify(e))}}},this.cid=e?.cid,this.appId=e?.appId,this.wecorp=new WxworkCorp(this.cid)}async syncGroupChat(e){let t=new Parse.Query("GroupChat");t.equalTo("chat_id",e?.chat_id);let r=await t.first();if(r?.id||(r=new Parse.Object("GroupChat")),!r?.get("joinUrl")){let t=(await this.wecorp.externalContact.groupChat.addJoinWay({scene:1,chat_id_list:[e.chat_id]}))?.config_id,o=(await this.wecorp.externalContact.groupChat.getJoinWay(t))?.join_way;r.set("joinUrl",o)}if(!r?.get("joinQrcode")){let t=(await this.wecorp.externalContact.groupChat.addJoinWay({scene:2,chat_id_list:[e.chat_id]}))?.config_id,o=(await this.wecorp.externalContact.groupChat.getJoinWay(t))?.join_way;r.set("joinQrcode",o)}let o={chat_id:e.chat_id,name:e.name,owner:e.owner,notice:e.notice},a=!1;return r.get("chat_id")!=e.chat_id&&(a=!0),r.get("name")!=e.name&&(a=!0),r.get("owner")!=e.owner&&(a=!0),r.get("notice")!=e.notice&&(a=!0),r.get("member_version")!=e.member_version&&(a=!0,o.member_list=e.member_list,o.member_version=e.member_version),r.set(o),a&&(r=await r.save()),r}async syncUserInfo(e){console.log("wework.syncUserInfo");let t=null;1==e.gender&&(t="男"),2==e.gender&&(t="女");let r=await this.getContactOrProfile(e);return console.log("thisUser",r),console.log("userInfo",e),"UserSocial"==r.className&&r.set({data:{openid:e.openid,userid:e.userid,external_userid:e.external_userid,type:e.type&&String(e.type)||null,name:e.name,avatar:e.avatar,gender:t,qr_code:e.qr_code,mobile:e.mobile,email:e.email,biz_mail:e.biz_mail,address:e.address,position:e.position,corp_name:e.corp_name},type:"wecom-agency",company:{__type:"Pointer",className:"Company",objectId:this.cid}}),"Profile"==r.className&&r.set({openid:e.openid,userid:e.userid,external_userid:e.external_userid,type:e.type&&String(e.type)||null,name:e.name,avatar:e.avatar,gender:t,qr_code:e.qr_code,mobile:e.mobile,email:e.email,biz_mail:e.biz_mail,address:e.address,position:e.position,corp_name:e.corp_name,company:{__type:"Pointer",className:"Company",objectId:this.cid},user:{__type:"Pointer",className:"_User",objectId:e.objectId}}),r=await r.save(),r}async getUserinfo(e){let t=localStorage.getItem(`${this.cid}/USERINFO`),r=JSON.parse(t);if(r)return r;if(!(e=new URL(location.href).searchParams.get("code")||e))return;let o=await this.wecorp.auth.getuserinfo(e);if(o?.errcode)return console.error(o?.errmsg),null;let a=o?.external_userid;if(a){let e=await this.wecorp.externalContact.get(a);e?.external_contact&&Object.keys(e?.external_contact).forEach((t=>{o[t]=e?.external_contact[t]}))}r=o;let i=await this.getContactOrProfile(r);return i?.get("mobile")&&(r.mobile=i?.get("mobile")),t=JSON.stringify(o),localStorage.setItem(`${this.cid}/USERINFO`,t),r}async getContactOrProfile(e){let t;(e.openid||e.external_userid)&&(t="UserSocial"),e.userid&&(t="Profile");let r=Parse.Object.extend(t),o=[];"Profile"==t&&(e.openid&&o.push({openid:{$regex:e.openid}}),e.userid&&o.push({userid:{$regex:e.userid}}),e.mobile&&o.push({mobile:{$regex:e.mobile}}),e.email&&o.push({email:{$regex:e.email}}),e.external_userid&&o.push({external_userid:{$regex:e.external_userid}})),(t="UserSocial")&&(e.openid&&o.push({"data.openid":{$regex:e.openid}}),e.userid&&o.push({"data.userid":{$regex:e.userid}}),e.mobile&&o.push({"data.mobile":{$regex:e.mobile}}),e.email&&o.push({"data.email":{$regex:e.email}}),e.external_userid&&o.push({"data.external_userid":{$regex:e.external_userid}}));let a,i=Parse.Query.fromJSON(t,{where:{$or:o}});i.equalTo("company",this.cid),i.equalTo("userid",e.userid);try{a=await i.first()}catch(e){console.error(e)}return a?.id||(a=new r),a}async loginPC(){let e=await this.getCorpByCid(this.cid);console.log(this.cid,e);let t=e?.corpId,r=e?.agentId,o=new URL("https://app.fmode.cn"+location.pathname+location?.search);o.searchParams.delete("code"),o.searchParams.delete("state");let a=encodeURIComponent(o.href),i=ww.WWLoginType.corpApp,n=ww.WWLoginRedirectType.callback;return console.log("loginPC1"),new Promise((e=>{console.log("loginPC2");const o=this.ww.createWWLoginPanel({el:"#ww_login",params:{login_type:i,appid:t,agentid:r,redirect_uri:a,state:"loginState",redirect_type:n},onCheckWeComLogin({isWeComLogin:t}){console.log(t),e("")},onLoginSuccess({code:t}){console.log({code:t}),e(t)},onLoginFail(t){console.error("lpc",t),e("")}});console.log(o,o.el)}))}async oauth(e="snsapi_base",t=!1){t&&localStorage.removeItem(`${this.cid}/USERINFO`);let r=await this.getCorpByCid(this.cid);console.log(this.cid,r);let o=r?.corpId,a=r?.agentId,i=new URL("https://app.fmode.cn"+location.pathname+location?.search);i.searchParams.delete("code"),i.searchParams.delete("state");let n=encodeURIComponent(i.href),s=`https://open.weixin.qq.com/connect/oauth2/authorize?appid=${o}&redirect_uri=${n}&response_type=code&scope=${e}&state=STATE&agentid=${a}#wechat_redirect`;if("h5"==this.platform()){if(location.host?.startsWith("localhost"))return"";s=`https://login.work.weixin.qq.com/wwlogin/sso/login?login_type=CorpApp&appid=${o}&agentid=${a}&redirect_uri=${n}&state=WWLogin`,console.log("createWWLoginPanel")}return location.href=s,null}async getCorpByCid(e){if(console.log("cid",e),this.corpId)return this.corpId;let t=new Parse.Query("CloudResource"),r=(await t.get(this.companyMap[e]?.corpResId)).get("config");return console.log("config",r),r}async registerCorpWithSuite(e,t,r){if("wxwork"!=this.platform())return!1;if(!r?.length&&this.registerUrl==location.href)return!0;r=r||jsApiList;try{e=e||this.cid,t=t||this.appId;let o=await this.getCorpByCid(e);console.log(o);let a=o?.corpId,i=this.suiteMap[t]?.suiteId;console.log(a,i);let n=new Date,s=new Promise((e=>{ww.register({corpId:o.corpId,suiteId:i,agentId:o.agentId,jsApiList:r,getAgentConfigSignature:async()=>{let e=await this.wecorp.ticket.get();return ww.getSignature({ticket:e,nonceStr:"666",timestamp:(n.getTime()/1e3).toFixed(0),url:location.href})},onAgentConfigSuccess:()=>{this.registerUrl=location.href,e(!0)},onAgentConfigFail:t=>{e(!1)},onConfigFail:t=>{e(!1)}})}));return await s}catch(e){return alert(JSON.stringify(e)),!1}}getUA(){return this.ua=navigator.userAgent.toLowerCase(),this.ua}platform(){return this.ua=navigator.userAgent.toLowerCase(),this.ua.indexOf("wxwork")>-1?"wxwork":this.ua.indexOf("wechat")>-1?"wechat":"h5"}async getContext(){await this.registerCorpWithSuite();try{let e=await ww.getContext();return e?.entry&&(this.entry=e?.entry),e}catch(e){this.entryError="请先注册JSAPI"+e.errCode+e.errMsg,console.error(e)}return null}async getCurrentChat(){let e;if(!await this.registerCorpWithSuite())return null;try{e=await ww.getContext()}catch(e){console.error(e)}let t,r,o,a,i=e?.entry;try{return"group_chat_tools"==i&&(t="chatId",r=(await ww.getCurExternalChat())?.chatId,a=await this.wecorp.externalContact.groupChat.get(r)),"contact_profile"!=i&&"single_chat_tools"!=i||(t="userId",r=(await ww.getCurExternalContact())?.userId,o=await this.wecorp.externalContact.get(r)),this.currentChat={type:t,id:r,group:a?.group_chat,contact:o?.external_contact,follow_user:o?.follow_user},this.currentChat}catch(e){return alert(JSON.stringify(e)),null}}version(){return alert(ww.SDK_VERSION),ww.SDK_VERSION}register(){ww.register({corpId:"ww7ca4776b2a70000",jsApiList:["getExternalContact"],getConfigSignature:this.getConfigSignature})}async getConfigSignature(e){return{timestamp:"",nonceStr:"",signature:""}}config(){}async selectEnterpriseContact(){let e=await ww.selectEnterpriseContact({fromDepartmentId:-1,mode:"multi",type:["department","user"]});console.log(e),alert(e)}}export const jsApiList=["getContext","getCurExternalChat","getCurExternalContact","createCorpGroupChat","updateCorpGroupChat","checkJsApi","onMenuShareAppMessage","onMenuShareWechat","onMenuShareTimeline","shareAppMessage","shareWechatMessage","startRecord","stopRecord","onVoiceRecordEnd","playVoice","pauseVoice","stopVoice","uploadVoice","downloadVoice","chooseImage","previewImage","uploadImage","downloadImage","getNetworkType","openLocation","getLocation","hideOptionMenu","showOptionMenu","hideMenuItems","showMenuItems","hideAllNonBaseMenuItem","showAllNonBaseMenuItem","closeWindow","scanQRCode","previewFile","openEnterpriseChat","selectEnterpriseContact","onHistoryBack","openDefaultBrowser"];
|
|
9
|
+
var MODULE_PATH_NEED = `6K+l5paH5Lu25piv5pys6aG555uu55qE5LiA6YOo5YiGIFRoaXMgZmlsZSBpcyBwYXJ0IG9mIHRoZSBDb21wb25lbnRzIGluIEZtb2RlIEluYy4KICAgIOeJiOadg+aJgOaciSDCqSDmnKrmnaXpo57pqawgwqkg5rGf6KW/6ISR5o6n56eR5oqA5pyJ6ZmQ5YWs5Y+4IENvcHlyaWdodCDCqSBGbW9kZSBUZWNobm9sb2d5IENvLiwgTHRkLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCBSaWdodHMgUmVzZXJ2ZWQuCiAgICDkuKXnpoHlnKjmnKrnu4/mjojmnYPnmoTmg4XlhrXkuIvvvIzpgJrov4fku7vkvZXlqpLku4vlpI3liLbmraTmlofku7YgVW5hdXRob3JpemVkIGNvcHlpbmcgb2YgdGhpcyBmaWxlLCB2aWEgYW55IG1lZGl1bSBpcyBzdHJpY3RseSBwcm9oaWJpdGVkCiAgICDor6Xmlofku7bmmK/kuJPmnInnmoTmnLrlr4bmlofku7YgUHJvcHJpZXRhcnkgYW5kIGNvbmZpZGVudGlhbAogICAKICAgIENvcHlyaWdodCAyMDIxLW5vdyBGbW9kZSBJbmMuIHN1cHBvcnRAZm1vZGUuY24uIDE4NjA3MDA3MDczLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCByaWdodHMgcmVzZXJ2ZWQuCgogICAgUEFUSDovaG9tZS9yeWFuL3dvcmtzcGFjZS9ub3ZhL25vdmEtYWRtaW4vZGlzdC9mbW9kZS1uZy9lc20yMDIyL2xpYi9jb3JlL3NvY2lhbC93eHdvcmsvd3h3b3JrLnNkay5tanM=`
|
|
10
|
+
|
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
* 保留所有权利 All Rights Reserved.
|
|
6
6
|
* /home/ryan/workspace/nova/nova-admin/dist/fmode-ng/esm2022/lib/social/index.mjs
|
|
7
7
|
*/
|
|
8
|
-
export*from"./wechat/wechat-jssdk.service";
|
|
8
|
+
export*from"./wechat/wechat-jssdk.service";export*from"./wxwork/wxwork-auth.guard";
|
|
9
9
|
var MODULE_PATH_NEED = `6K+l5paH5Lu25piv5pys6aG555uu55qE5LiA6YOo5YiGIFRoaXMgZmlsZSBpcyBwYXJ0IG9mIHRoZSBDb21wb25lbnRzIGluIEZtb2RlIEluYy4KICAgIOeJiOadg+aJgOaciSDCqSDmnKrmnaXpo57pqawgwqkg5rGf6KW/6ISR5o6n56eR5oqA5pyJ6ZmQ5YWs5Y+4IENvcHlyaWdodCDCqSBGbW9kZSBUZWNobm9sb2d5IENvLiwgTHRkLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCBSaWdodHMgUmVzZXJ2ZWQuCiAgICDkuKXnpoHlnKjmnKrnu4/mjojmnYPnmoTmg4XlhrXkuIvvvIzpgJrov4fku7vkvZXlqpLku4vlpI3liLbmraTmlofku7YgVW5hdXRob3JpemVkIGNvcHlpbmcgb2YgdGhpcyBmaWxlLCB2aWEgYW55IG1lZGl1bSBpcyBzdHJpY3RseSBwcm9oaWJpdGVkCiAgICDor6Xmlofku7bmmK/kuJPmnInnmoTmnLrlr4bmlofku7YgUHJvcHJpZXRhcnkgYW5kIGNvbmZpZGVudGlhbAogICAKICAgIENvcHlyaWdodCAyMDIxLW5vdyBGbW9kZSBJbmMuIHN1cHBvcnRAZm1vZGUuY24uIDE4NjA3MDA3MDczLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCByaWdodHMgcmVzZXJ2ZWQuCgogICAgUEFUSDovaG9tZS9yeWFuL3dvcmtzcGFjZS9ub3ZhL25vdmEtYWRtaW4vZGlzdC9mbW9kZS1uZy9lc20yMDIyL2xpYi9zb2NpYWwvaW5kZXgubWpz`
|
|
10
10
|
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @copyright © 未来飞马 © 未来全栈 www.fmode.cn
|
|
4
|
+
* 版权所有 © 未来飞马 © 江西脑控科技有限公司 Copyright © Fmode Technology Co., Ltd.
|
|
5
|
+
* 保留所有权利 All Rights Reserved.
|
|
6
|
+
* /home/ryan/workspace/nova/nova-admin/dist/fmode-ng/esm2022/lib/social/wxwork/wxwork-auth.guard.mjs
|
|
7
|
+
*/
|
|
8
|
+
import{WxworkSDK}from"../../core/social/wxwork/wxwork.sdk";import{openMobileBindModal}from"../../user/comp-mobile-bind/comp-mobile-bind.component";import{ModalController}from"@ionic/angular/standalone";export const WxworkAuthGuard=async(o,e)=>{const r=new ModalController;let n=o.paramMap.get("cid")||o.queryParamMap.get("cid"),a=new WxworkSDK({cid:n,appId:"crm"}),t=await a.getUserinfo();console.log("guard userInfo",t);try{if(t)return await syncUserInfo(t,n,a,r),!0}catch(o){console.error(o)}let i=new URL(location?.href).searchParams.get("code");if(!i){let o=navigator.userAgent.toLowerCase();if(console.log("ua",o),-1!==o.indexOf("micromessenger")){let o="snsapi_base";"wechat"==a.platform()&&(o="snsapi_base"),"wxwork"==a.platform()&&(o="snsapi_privateinfo");let e=await a.oauth(o);return e&&(i=e),!1}i||(i=await a.loginPC())}return t=await a.getUserinfo(i),await syncUserInfo(t,n,a,r),!0};async function syncUserInfo(o,e,r,n){if(console.log("syncUserInfo"),!o?.mobile){console.log("modalController");let r=await openMobileBindModal(n,{cid:e});if(!r)return!1;o.mobile=r}r.syncUserInfo(o)}
|
|
9
|
+
var MODULE_PATH_NEED = `6K+l5paH5Lu25piv5pys6aG555uu55qE5LiA6YOo5YiGIFRoaXMgZmlsZSBpcyBwYXJ0IG9mIHRoZSBDb21wb25lbnRzIGluIEZtb2RlIEluYy4KICAgIOeJiOadg+aJgOaciSDCqSDmnKrmnaXpo57pqawgwqkg5rGf6KW/6ISR5o6n56eR5oqA5pyJ6ZmQ5YWs5Y+4IENvcHlyaWdodCDCqSBGbW9kZSBUZWNobm9sb2d5IENvLiwgTHRkLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCBSaWdodHMgUmVzZXJ2ZWQuCiAgICDkuKXnpoHlnKjmnKrnu4/mjojmnYPnmoTmg4XlhrXkuIvvvIzpgJrov4fku7vkvZXlqpLku4vlpI3liLbmraTmlofku7YgVW5hdXRob3JpemVkIGNvcHlpbmcgb2YgdGhpcyBmaWxlLCB2aWEgYW55IG1lZGl1bSBpcyBzdHJpY3RseSBwcm9oaWJpdGVkCiAgICDor6Xmlofku7bmmK/kuJPmnInnmoTmnLrlr4bmlofku7YgUHJvcHJpZXRhcnkgYW5kIGNvbmZpZGVudGlhbAogICAKICAgIENvcHlyaWdodCAyMDIxLW5vdyBGbW9kZSBJbmMuIHN1cHBvcnRAZm1vZGUuY24uIDE4NjA3MDA3MDczLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCByaWdodHMgcmVzZXJ2ZWQuCgogICAgUEFUSDovaG9tZS9yeWFuL3dvcmtzcGFjZS9ub3ZhL25vdmEtYWRtaW4vZGlzdC9mbW9kZS1uZy9lc20yMDIyL2xpYi9zb2NpYWwvd3h3b3JrL3d4d29yay1hdXRoLmd1YXJkLm1qcw==`
|
|
10
|
+
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @copyright © 未来飞马 © 未来全栈 www.fmode.cn
|
|
4
|
+
* 版权所有 © 未来飞马 © 江西脑控科技有限公司 Copyright © Fmode Technology Co., Ltd.
|
|
5
|
+
* 保留所有权利 All Rights Reserved.
|
|
6
|
+
* /home/ryan/workspace/nova/nova-admin/dist/fmode-ng/esm2022/lib/user/comp-mobile-bind/comp-mobile-bind.component.mjs
|
|
7
|
+
*/
|
|
8
|
+
import{Component,Input,ViewChild}from"@angular/core";import{IonHeader,IonToolbar,IonTitle,IonContent,IonCard,IonCardContent,IonButton,IonCardHeader,IonCardTitle,IonCardSubtitle,ModalController,IonInput,IonItem,IonSegment,IonSegmentButton,IonLabel,AlertController}from"@ionic/angular/standalone";import{NovaCloudService}from"../../nova-cloud/nova-cloud.service";import{FmodeParse}from"../../core/parse";import*as i0 from"@angular/core";import*as i1 from"@ionic/angular/standalone";import*as i2 from"../../nova-cloud/nova-cloud.service";const Parse=FmodeParse.with("nova");export class CompMobileBindComponent{mobileChange(n){console.log(n),this.mobile=n?.detail?.value}codeChange(n){this.code=n?.detail?.value}async sendSmsCode(){this.startCountdown();/^1[3-9]\d{9}$/.test(this.mobile)?(await this.ncloud.apig("message",{company:this.cid,mobile:this.mobile},"POST"),this.isSended=!0,setTimeout((()=>{this.codeInput?.setFocus()}),500)):this.presentAlert("请检查手机号")}startCountdown(){this.countdown=60,this.countInt=setInterval((()=>{this.countdown--,0==this.countdown&&this.countInt&&clearInterval(this.countInt)}),1e3)}async presentAlert(n){const e=await this.alertCtrl.create({header:"提示",subHeader:n,buttons:["确定"]});await e.present()}constructor(n,e,o){this.modalCtrl=n,this.alertCtrl=e,this.ncloud=o,this.mobile="",this.code="",this.isSended=!1,this.countdown=0,this.isVerifying=!1}ngAfterViewInit(){setTimeout((()=>{this.mobileInput.setFocus()}),500)}async verifyMobile(){if(this.isVerifying)return;this.isVerifying=!0;let n=await this.ncloud.api(`/auth/mobile?company=${this.cid}&mobile=${this.mobile}&code=${this.code}`,null,"GET");if(n?.token){console.log(200,n);let e=await Parse.User.become(n.token);e?.id&&(this.modalCtrl.dismiss({mobile:this.mobile,user:e},"confirm"),this.countInt&&clearInterval(this.countInt))}this.isVerifying=!1}static{this.ɵfac=i0.ɵɵngDeclareFactory({minVersion:"12.0.0",version:"17.3.12",ngImport:i0,type:CompMobileBindComponent,deps:[{token:i1.ModalController},{token:i1.AlertController},{token:i2.NovaCloudService}],target:i0.ɵɵFactoryTarget.Component})}static{this.ɵcmp=i0.ɵɵngDeclareComponent({minVersion:"17.0.0",version:"17.3.12",type:CompMobileBindComponent,isStandalone:!0,selector:"app-comp-mobile-bind",inputs:{cid:"cid"},viewQueries:[{propertyName:"mobileInput",first:!0,predicate:["mobileInput"],descendants:!0,read:IonInput},{propertyName:"codeInput",first:!0,predicate:["codeInput"],descendants:!0,read:IonInput}],ngImport:i0,template:'\x3c!-- 用户登录状态 --\x3e\n<ion-card>\n <ion-card-header>\n <ion-card-title>\n 验证手机\n \x3c!-- <ion-segment [value]="type" (ionChange)="typeChange($event)">\n <ion-segment-button value="login">\n <ion-label>登录</ion-label>\n </ion-segment-button>\n <ion-segment-button value="signup">\n <ion-label>注册</ion-label>\n </ion-segment-button>\n </ion-segment> --\x3e\n </ion-card-title>\n \x3c!-- <ion-card-subtitle>请输入账号密码</ion-card-subtitle> --\x3e\n </ion-card-header>\n <ion-card-content>\n <ion-item>\n <ion-input #mobileInput [value]="mobile" (ionChange)="mobileChange($event)" label="手机号" placeholder="请您输入手机号"></ion-input>\n </ion-item>\n @if(isSended){\n <ion-item>\n <ion-input #codeInput [value]="code" (ionChange)="codeChange($event)" label="验证码" placeholder="请您输入6位数字"></ion-input>\n @if(countdown){\n <ion-button color="light">{{countdown}}</ion-button>\n }\n </ion-item>\n }\n @if(!countdown){\n <ion-button expand="block" (click)="sendSmsCode()">获取验证码</ion-button>\n }\n @if(isSended && countdown){\n <ion-button expand="block" (click)="verifyMobile()" [disabled]="isVerifying">确认</ion-button>\n }\n </ion-card-content>\n </ion-card>',styles:[""],dependencies:[{kind:"component",type:IonCard,selector:"ion-card",inputs:["button","color","disabled","download","href","mode","rel","routerAnimation","routerDirection","target","type"]},{kind:"component",type:IonCardContent,selector:"ion-card-content",inputs:["mode"]},{kind:"component",type:IonButton,selector:"ion-button",inputs:["buttonType","color","disabled","download","expand","fill","form","href","mode","rel","routerAnimation","routerDirection","shape","size","strong","target","type"]},{kind:"component",type:IonCardHeader,selector:"ion-card-header",inputs:["color","mode","translucent"]},{kind:"component",type:IonCardTitle,selector:"ion-card-title",inputs:["color","mode"]},{kind:"component",type:IonInput,selector:"ion-input",inputs:["accept","autocapitalize","autocomplete","autocorrect","autofocus","clearInput","clearOnEdit","color","counter","counterFormatter","debounce","disabled","enterkeyhint","errorText","fill","helperText","inputmode","label","labelPlacement","max","maxlength","min","minlength","mode","multiple","name","pattern","placeholder","readonly","required","shape","size","spellcheck","step","type","value"]},{kind:"component",type:IonItem,selector:"ion-item",inputs:["button","color","detail","detailIcon","disabled","download","href","lines","mode","rel","routerAnimation","routerDirection","target","type"]}]})}}i0.ɵɵngDeclareClassMetadata({minVersion:"12.0.0",version:"17.3.12",ngImport:i0,type:CompMobileBindComponent,decorators:[{type:Component,args:[{selector:"app-comp-mobile-bind",standalone:!0,imports:[IonHeader,IonToolbar,IonTitle,IonContent,IonCard,IonCardContent,IonButton,IonCardHeader,IonCardTitle,IonCardSubtitle,IonInput,IonItem,IonSegment,IonSegmentButton,IonLabel],template:'\x3c!-- 用户登录状态 --\x3e\n<ion-card>\n <ion-card-header>\n <ion-card-title>\n 验证手机\n \x3c!-- <ion-segment [value]="type" (ionChange)="typeChange($event)">\n <ion-segment-button value="login">\n <ion-label>登录</ion-label>\n </ion-segment-button>\n <ion-segment-button value="signup">\n <ion-label>注册</ion-label>\n </ion-segment-button>\n </ion-segment> --\x3e\n </ion-card-title>\n \x3c!-- <ion-card-subtitle>请输入账号密码</ion-card-subtitle> --\x3e\n </ion-card-header>\n <ion-card-content>\n <ion-item>\n <ion-input #mobileInput [value]="mobile" (ionChange)="mobileChange($event)" label="手机号" placeholder="请您输入手机号"></ion-input>\n </ion-item>\n @if(isSended){\n <ion-item>\n <ion-input #codeInput [value]="code" (ionChange)="codeChange($event)" label="验证码" placeholder="请您输入6位数字"></ion-input>\n @if(countdown){\n <ion-button color="light">{{countdown}}</ion-button>\n }\n </ion-item>\n }\n @if(!countdown){\n <ion-button expand="block" (click)="sendSmsCode()">获取验证码</ion-button>\n }\n @if(isSended && countdown){\n <ion-button expand="block" (click)="verifyMobile()" [disabled]="isVerifying">确认</ion-button>\n }\n </ion-card-content>\n </ion-card>'}]}],ctorParameters:()=>[{type:i1.ModalController},{type:i1.AlertController},{type:i2.NovaCloudService}],propDecorators:{mobileInput:[{type:ViewChild,args:["mobileInput",{read:IonInput}]}],codeInput:[{type:ViewChild,args:["codeInput",{read:IonInput}]}],cid:[{type:Input}]}});export async function openMobileBindModal(n,e){console.log("openMobileBindModal");let o=Parse.User.current();if(o?.get("mobile"))return o?.get("mobile");let t=await n.create({component:CompMobileBindComponent,componentProps:{cid:e?.cid},cssClass:"modal-mobile-bind",backdropDismiss:!1,keyboardClose:!1,breakpoints:[.3,.5],initialBreakpoint:.3});await t.present();const{data:i,role:a}=await t.onWillDismiss();return"confirm"===a&&i?.mobile?i.mobile:null}
|
|
9
|
+
var MODULE_PATH_NEED = `6K+l5paH5Lu25piv5pys6aG555uu55qE5LiA6YOo5YiGIFRoaXMgZmlsZSBpcyBwYXJ0IG9mIHRoZSBDb21wb25lbnRzIGluIEZtb2RlIEluYy4KICAgIOeJiOadg+aJgOaciSDCqSDmnKrmnaXpo57pqawgwqkg5rGf6KW/6ISR5o6n56eR5oqA5pyJ6ZmQ5YWs5Y+4IENvcHlyaWdodCDCqSBGbW9kZSBUZWNobm9sb2d5IENvLiwgTHRkLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCBSaWdodHMgUmVzZXJ2ZWQuCiAgICDkuKXnpoHlnKjmnKrnu4/mjojmnYPnmoTmg4XlhrXkuIvvvIzpgJrov4fku7vkvZXlqpLku4vlpI3liLbmraTmlofku7YgVW5hdXRob3JpemVkIGNvcHlpbmcgb2YgdGhpcyBmaWxlLCB2aWEgYW55IG1lZGl1bSBpcyBzdHJpY3RseSBwcm9oaWJpdGVkCiAgICDor6Xmlofku7bmmK/kuJPmnInnmoTmnLrlr4bmlofku7YgUHJvcHJpZXRhcnkgYW5kIGNvbmZpZGVudGlhbAogICAKICAgIENvcHlyaWdodCAyMDIxLW5vdyBGbW9kZSBJbmMuIHN1cHBvcnRAZm1vZGUuY24uIDE4NjA3MDA3MDczLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCByaWdodHMgcmVzZXJ2ZWQuCgogICAgUEFUSDovaG9tZS9yeWFuL3dvcmtzcGFjZS9ub3ZhL25vdmEtYWRtaW4vZGlzdC9mbW9kZS1uZy9lc20yMDIyL2xpYi91c2VyL2NvbXAtbW9iaWxlLWJpbmQvY29tcC1tb2JpbGUtYmluZC5jb21wb25lbnQubWpz`
|
|
10
|
+
|
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
* 保留所有权利 All Rights Reserved.
|
|
6
6
|
* /home/ryan/workspace/nova/nova-admin/dist/fmode-ng/esm2022/lib/user/index.mjs
|
|
7
7
|
*/
|
|
8
|
-
export*from"./comp-user-avatar/comp-user-avatar.component";export*from"./login/auth.service";export*from"./account/account.service";export*from"./user.module";export*from"./user-name.pipe";export*from"./staff";export*from"./profile/auth-profile.guard";export*from"./profile/auth-profile.service";export*from"./profile/profile-bind/profile-bind.component";export*from"./profile/profile.module";export*from"./modal-user-login/modal-user-login.component";export*from"./login/auth.guard";export*from"./login/auth.service";export*from"./login/login.component";export*from"./account/account.service";export*from"./captcha/captcha.component";
|
|
8
|
+
export*from"./comp-user-avatar/comp-user-avatar.component";export*from"./login/auth.service";export*from"./account/account.service";export*from"./user.module";export*from"./user-name.pipe";export*from"./staff";export*from"./profile/auth-profile.guard";export*from"./profile/auth-profile.service";export*from"./profile/profile-bind/profile-bind.component";export*from"./profile/profile.module";export*from"./modal-user-login/modal-user-login.component";export*from"./login/auth.guard";export*from"./login/auth.service";export*from"./login/login.component";export*from"./comp-mobile-bind/comp-mobile-bind.component";export*from"./account/account.service";export*from"./captcha/captcha.component";
|
|
9
9
|
var MODULE_PATH_NEED = `6K+l5paH5Lu25piv5pys6aG555uu55qE5LiA6YOo5YiGIFRoaXMgZmlsZSBpcyBwYXJ0IG9mIHRoZSBDb21wb25lbnRzIGluIEZtb2RlIEluYy4KICAgIOeJiOadg+aJgOaciSDCqSDmnKrmnaXpo57pqawgwqkg5rGf6KW/6ISR5o6n56eR5oqA5pyJ6ZmQ5YWs5Y+4IENvcHlyaWdodCDCqSBGbW9kZSBUZWNobm9sb2d5IENvLiwgTHRkLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCBSaWdodHMgUmVzZXJ2ZWQuCiAgICDkuKXnpoHlnKjmnKrnu4/mjojmnYPnmoTmg4XlhrXkuIvvvIzpgJrov4fku7vkvZXlqpLku4vlpI3liLbmraTmlofku7YgVW5hdXRob3JpemVkIGNvcHlpbmcgb2YgdGhpcyBmaWxlLCB2aWEgYW55IG1lZGl1bSBpcyBzdHJpY3RseSBwcm9oaWJpdGVkCiAgICDor6Xmlofku7bmmK/kuJPmnInnmoTmnLrlr4bmlofku7YgUHJvcHJpZXRhcnkgYW5kIGNvbmZpZGVudGlhbAogICAKICAgIENvcHlyaWdodCAyMDIxLW5vdyBGbW9kZSBJbmMuIHN1cHBvcnRAZm1vZGUuY24uIDE4NjA3MDA3MDczLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCByaWdodHMgcmVzZXJ2ZWQuCgogICAgUEFUSDovaG9tZS9yeWFuL3dvcmtzcGFjZS9ub3ZhL25vdmEtYWRtaW4vZGlzdC9mbW9kZS1uZy9lc20yMDIyL2xpYi91c2VyL2luZGV4Lm1qcw==`
|
|
10
10
|
|