| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080 |
- "use strict";
- const common_vendor = require("../../common/vendor.js");
- const common_config = require("../../common/config.js");
- let hiddenCanvasNodeRef = null;
- let hiddenCanvasCtxRef = null;
- const _sfc_main = {
- name: "IdentityVerify",
- data() {
- return {
- followUpQuestion: "",
- // 追问问题
- followUpAudioUrl: "",
- // 追问音频URL
- audioContext: null,
- // 音频上下文
- followUpQuestions: [],
- // 追问问题列表
- // 帧抓取相关
- frameListener: null,
- isFrameCapturing: false,
- lastFrameCaptureAt: 0,
- frameCaptureIntervalMs: 5e3,
- frameCanvasWidth: 320,
- frameCanvasHeight: 240,
- hiddenCanvasNode: null,
- // 仅用于调试展示,不在渲染中直接使用
- hiddenCanvasCtx: null,
- // 仅用于调试展示,不在渲染中直接使用
- hiddenCanvasReady: false,
- isWaitingForAnswer: false,
- // 添加新的状态来控制是否在等待用户回答
- currentFollowUpIndex: -1,
- // 当前追问问题索引
- showSubtitleText: false,
- // 是否显示字幕
- subtitleText: "",
- // 字幕文本
- parentQuestion: "",
- // 父问题文本
- isFollowUpQuestion: false,
- // 是否是追问问题
- loading: false,
- responses: [],
- processedResponses: [],
- assistantResponse: "",
- audioTranscript: "",
- videoPlaying: false,
- showDebugInfo: false,
- // 设置为true可以显示调试信息
- videoUrl: "",
- // 修改为空字符串,将通过API获取
- showReplayButton: false,
- cameraStream: null,
- // 存储摄像头流
- cameraError: null,
- // 存储摄像头错误信息
- useMiniProgramCameraComponent: false,
- // 添加小程序相机组件标志
- cameraContext: null,
- // 添加相机上下文
- currentSubtitle: "",
- currentTranslation: "",
- // 添加翻译文本
- subtitles: [],
- // 修改为空数组,将通过API获取
- // 移除硬编码的字幕数组
- // secondVideoSubtitles: [...],
- // thirdVideoSubtitles: [...],
- // 等等...
- showAnswerButton: false,
- // 控制答题按钮显示
- currentVideoIndex: 0,
- // 当前播放的视频索引
- videoList: [],
- // 修改为空数组,将通过API获取
- // 其他属性保持不变...
- questions: [],
- // 添加新属性存储API返回的问题数据
- introVideoUrl: (() => {
- const DEFAULT_VIDEO_URL = "https://data.qicai321.com/minlong/ee4d9cce-c3d5-4350-8c6e-684283827897.mp4";
- try {
- const configStr = common_vendor.index.getStorageSync("configData");
- if (!configStr)
- return DEFAULT_VIDEO_URL;
- const config = JSON.parse(configStr);
- return config.digital_human_opening_video_url || DEFAULT_VIDEO_URL;
- } catch (error) {
- console.warn("解析配置数据失败:", error);
- return DEFAULT_VIDEO_URL;
- }
- })(),
- //'https://data.qicai321.com/minlong/ee4d9cce-c3d5-4350-8c6e-684283827897.mp4', // 保留介绍视频
- isRecording: false,
- recordingTimer: null,
- showStopRecordingButton: false,
- mediaRecorder: null,
- recordedChunks: [],
- recorder: null,
- lastUploadedVideoUrl: "",
- showStartRecordingButton: false,
- showRetryButton: false,
- // 控制重试按钮显示
- lastVideoToRetry: null,
- // 存储上次失败的视频URL,用于重试
- recordingStartTime: null,
- // 录制开始时间
- recordingTimerCount: 0,
- // 录制计时器计数
- recordingTimeDisplay: "00:00",
- // 格式化的录制时间显示
- // 添加上传队列相关数据
- uploadQueue: [],
- // 存储待上传的视频
- backgroundUploadQueue: [],
- // 存储后台上传的视频
- isUploading: false,
- // 标记是否正在上传
- uploadProgress: {},
- // 存储每个视频的上传进度
- uploadStatus: {},
- // 存储每个视频的上传状态
- showUploadStatus: false,
- // 是否显示上传状态指示器
- uploadStatusText: "",
- // 上传状态文本
- mediaRecorderTimeout: null,
- // 用于存储MediaRecorder的超时机制
- maxRecordingTime: 300,
- // 最大录制时间(秒)- 从60秒改为300秒(5分钟)
- remainingTime: 300,
- // 剩余录制时间(秒)- 从60秒改为300秒
- countdownValue: 10,
- // 倒计时数值
- showCountdown: false,
- // 是否显示倒计时蒙层
- countdownTimer: null,
- showGif: false,
- // 控制是否显示GIF
- gifUrl: "",
- // GIF图片的URL
- globalSocketTask: null,
- // 添加全局 WebSocket 连接对象
- lowScoreVideoUrl: (() => {
- var _a;
- const DEFAULT_VIDEO_URL = "https://data.qicai321.com/minlong/latentsync/0530e7f5-1957-422d-8f34-ba4a92608081_result.mp4";
- try {
- const configStr = common_vendor.index.getStorageSync("configData");
- if (!configStr)
- return DEFAULT_VIDEO_URL;
- const config = JSON.parse(configStr);
- return ((_a = config.digital_human) == null ? void 0 : _a.middle_video_url) || DEFAULT_VIDEO_URL;
- } catch (error) {
- console.warn("解析配置数据失败:", error);
- return DEFAULT_VIDEO_URL;
- }
- })(),
- //'https://data.qicai321.com/minlong/latentsync/0530e7f5-1957-422d-8f34-ba4a92608081_result.mp4', // 低分提示视频URL
- showRerecordButton: false,
- // 控制重新录制按钮显示
- isPlayingLowScoreVideo: false,
- // 标记是否正在播放低分提示视频
- lowScoreVideoSubtitles: [
- {
- startTime: 0,
- endTime: 10,
- // 假设视频长度为10秒,可根据实际情况调整
- text: "我未听清楚您在说什么,请您再说一遍!"
- }
- ],
- // 用于存储低分提示视频的字幕
- retryCount: 0,
- // 添加重试次数计数器
- maxRetryAttempts: 2,
- // 最大重试次数限制
- needPlayLowScoreVideo: false,
- // 是否需要播放低分视频
- finalRecordingDuration: 0,
- // 最终录制时长
- historyTime: 0,
- // 添加历史时间记录
- followUpQuestions: [],
- // 存储追问问题数据
- currentParentQuestionId: null,
- // 当前父问题ID
- hasPlayedFollowUp: {},
- // 记录已播放的追问,格式: {questionId: true}
- isFollowUpQuestion: false,
- // 标记当前是否正在播放追问问题
- currentFollowUpQuestion: null,
- // 添加当前追问问题的完整信息
- lastQuestionWasFollowUp: false,
- lastFollowUpQuestionId: null,
- // 追问次数控制 - 统一使用job_position_question_id作为key
- defaultFollowUpLimit: 1,
- // 默认每个主题目最多1次追问
- followUpLimitMap: {},
- // { job_position_question_id: limit }
- followUpAskedCountMap: {},
- // { job_position_question_id: askedCount }
- followUpRequestInFlight: {},
- // { job_position_question_id: boolean }
- lastUpdateTime: Date.now(),
- // 添加最后更新时间戳
- subtitleMap: {},
- // 用于存储字幕和翻译的映射
- progressPercent: 0,
- // 录制进度百分比
- progressColor: "#05dc8b",
- // 进度条颜色
- progressBgColor: "rgba(0, 0, 0,0.3)",
- // 进度条背景色
- parentQuestion: "",
- // 添加父问题存储
- screenCaptureCount: 0,
- // 添加截屏次数记录
- personDetectionSocket: null,
- // WebSocket对象
- personDetectionInterval: null,
- // 定时器对象
- showCameraWarning: false,
- // 添加新的数据属性
- showPageWarning: false,
- // 添加新的数据属性
- showPageDRWarning: false,
- //多人提示
- followUpQuestion: "",
- // 追问问题
- followUpAudioUrl: "",
- // 追问音频URL
- audioContext: null,
- // 音频上下文
- followUpQuestions: [],
- // 追问问题列表
- currentFollowUpIndex: -1,
- // 当前追问问题索引
- showSubtitleText: false,
- // 是否显示字幕
- subtitleText: "",
- // 字幕文本
- isAudioPlaying: false,
- isWaitingForAnswer: false,
- // 添加新的状态来控制是否在等待用户回答
- currentRecordingDuration: 0,
- // 添加当前录制时长
- parentJobPositionQuestionId: null,
- // 添加父问题的job_position_question_id
- isFollowUpMode: false,
- // 是否处于追问模式
- mainQuestionIndex: 0,
- // 当前主问题的索引
- isVideoSwitching: false,
- // 添加视频切换状态锁
- originalQuestionSubtitle: null,
- // 保存原始字幕信息
- isThinking: false,
- // 面试官思考中状态
- thinkingTimer: null,
- // 思考计时器
- questionRetryMap: {},
- // 用于跟踪每个问题的重试次数
- maxQuestionRetries: 2,
- // 每个问题最大重试次数
- statusBarHeight: 0
- };
- },
- onLoad() {
- this.statusBarHeight = common_vendor.index.getSystemInfoSync().statusBarHeight || 0;
- const systemInfo = common_vendor.index.getSystemInfoSync();
- const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith("mp-");
- if (isMiniProgram) {
- this.initPersonDetectionWebSocket();
- }
- },
- onReady() {
- this.initHiddenCanvasNode(true);
- },
- mounted() {
- this.fetchQuestions();
- this.checkAudioPermission();
- this.initCamera();
- this.checkIOSCameraRecordPermission();
- this.checkAndFixRenderingIssues();
- setTimeout(() => {
- if (this.cameraStream && !this.useMiniProgramCameraComponent) {
- this.testAudioInput();
- }
- }, 3e3);
- this.historyTime = 0;
- common_vendor.index.setKeepScreenOn({
- keepScreenOn: true
- });
- common_vendor.index.onUserCaptureScreen(() => {
- console.log("User captured screen");
- this.screenCaptureCount++;
- if (this.screenCaptureCount === 1) {
- common_vendor.index.showModal({
- title: "Warning",
- content: "检测到屏幕截图。如果你再次捕捉屏幕,你的面试将无效.",
- showCancel: false,
- confirmText: "OK"
- });
- } else if (this.screenCaptureCount >= 2) {
- common_vendor.index.showModal({
- title: "Interview Invalid",
- content: "由于多次屏幕截图,您的面试已无效。请联系招聘人员寻求帮助.",
- showCancel: false,
- confirmText: "OK",
- success: () => {
- this.invalidateInterview();
- }
- });
- }
- });
- this.initHiddenCanvasNode(false);
- },
- beforeDestroy() {
- common_vendor.index.offUserCaptureScreen();
- this.cleanupPersonDetectionWebSocket();
- },
- methods: {
- // 初始化隐藏canvas,支持重试
- initHiddenCanvasNode(fromReady = false, retries = 3) {
- if (!this.useMiniProgramCameraComponent)
- return;
- try {
- const query = common_vendor.index.createSelectorQuery().in(this);
- query.select("#hiddenCaptureCanvas").fields({ node: true, size: true }).exec((res) => {
- const canvasNode = res && res[0] && res[0].node;
- if (canvasNode && canvasNode.getContext) {
- hiddenCanvasNodeRef = canvasNode;
- hiddenCanvasCtxRef = canvasNode.getContext("2d");
- this.hiddenCanvasNode = canvasNode;
- this.hiddenCanvasCtx = hiddenCanvasCtxRef;
- this.hiddenCanvasReady = true;
- console.info("隐藏canvas初始化成功(fromReady:", fromReady, ")");
- } else {
- console.warn("隐藏canvas未获取到node或不支持2D上下文(fromReady:", fromReady, ")");
- if (retries > 0) {
- setTimeout(() => this.initHiddenCanvasNode(fromReady, retries - 1), 300);
- }
- }
- });
- } catch (e) {
- console.warn("初始化隐藏canvas失败:", e);
- if (retries > 0) {
- setTimeout(() => this.initHiddenCanvasNode(fromReady, retries - 1), 300);
- }
- }
- },
- // 安全拍照再发送(非录制期)
- safeTakePhotoAndSend() {
- if (this.isFrameCapturing)
- return;
- if (!this.personDetectionSocket || this.personDetectionSocket.readyState !== 1)
- return;
- this.isFrameCapturing = true;
- try {
- this.cameraContext.takePhoto({
- quality: "low",
- success: (res) => {
- const tempFilePath = res && res.tempImagePath;
- if (!tempFilePath) {
- this.isFrameCapturing = false;
- return;
- }
- common_vendor.index.getFileSystemManager().readFile({
- filePath: tempFilePath,
- encoding: "base64",
- success: (r) => {
- try {
- const base64Image = r.data;
- if (!this.personDetectionSocket || this.personDetectionSocket.readyState !== 1) {
- return;
- }
- this.personDetectionSocket.send({
- data: JSON.stringify({
- type: "person_detection",
- image_data: base64Image
- })
- });
- } finally {
- this.isFrameCapturing = false;
- }
- },
- fail: () => {
- this.isFrameCapturing = false;
- }
- });
- },
- fail: () => {
- this.isFrameCapturing = false;
- }
- });
- } catch (e) {
- this.isFrameCapturing = false;
- }
- },
- // 录制期间抓帧并经隐藏canvas导出为图片再发送(持续监听 + 节流)
- startFrameStreamCapture() {
- if (!this.useMiniProgramCameraComponent) {
- console.warn("帧抓取:非小程序相机,跳过");
- return;
- }
- if (!this.cameraContext || !this.cameraContext.onCameraFrame) {
- console.warn("帧抓取:cameraContext或onCameraFrame不可用");
- return;
- }
- if (this.frameListener && this.frameListener.stop) {
- return;
- }
- try {
- const listener = this.cameraContext.onCameraFrame((frame) => {
- const now = Date.now();
- if (now - this.lastFrameCaptureAt < (this.frameCaptureIntervalMs || 5e3))
- return;
- if (this.isFrameCapturing)
- return;
- if (!this.hiddenCanvasReady || !hiddenCanvasCtxRef || !hiddenCanvasNodeRef) {
- console.warn("帧抓取:隐藏canvas未就绪");
- this.initHiddenCanvasNode(false, 2);
- return;
- }
- if (!this.personDetectionSocket || this.personDetectionSocket.readyState !== 1) {
- console.warn("帧抓取:WebSocket未就绪");
- return;
- }
- this.isFrameCapturing = true;
- this.lastFrameCaptureAt = now;
- try {
- const raw = frame && frame.data;
- const frameW = frame && frame.width || this.frameCanvasWidth;
- const frameH = frame && frame.height || this.frameCanvasHeight;
- const canvas = hiddenCanvasNodeRef;
- if (!canvas) {
- throw new Error("hiddenCanvasNode is undefined");
- }
- canvas.width = frameW;
- canvas.height = frameH;
- const ctx = hiddenCanvasCtxRef;
- if (!raw) {
- throw new Error("frame.data is undefined");
- }
- const rgba = raw instanceof Uint8ClampedArray ? raw : new Uint8ClampedArray(raw);
- const imageData = ctx.createImageData(frameW, frameH);
- imageData.data.set(rgba);
- ctx.putImageData(imageData, 0, 0);
- const exportSuccess = (tempFilePath) => {
- common_vendor.index.getFileSystemManager().readFile({
- filePath: tempFilePath,
- encoding: "base64",
- success: (r) => {
- if (this.personDetectionSocket && this.personDetectionSocket.readyState === 1) {
- this.personDetectionSocket.send({
- data: JSON.stringify({ type: "person_detection", image_data: r.data })
- });
- console.info("帧抓取:已发送图片");
- }
- this.isFrameCapturing = false;
- },
- fail: () => {
- console.warn("帧抓取:读取临时图片失败");
- this.isFrameCapturing = false;
- }
- });
- };
- const doExport = () => {
- if (canvas && typeof canvas.toTempFilePath === "function") {
- canvas.toTempFilePath({
- fileType: "jpg",
- quality: 0.5,
- success: (res) => exportSuccess(res.tempFilePath),
- fail: (err) => {
- console.warn("帧抓取:node.toTempFilePath 失败,回退到uni.canvasToTempFilePath", err);
- common_vendor.index.canvasToTempFilePath({
- canvas: hiddenCanvasNodeRef,
- x: 0,
- y: 0,
- width: frameW,
- height: frameH,
- destWidth: frameW,
- destHeight: frameH,
- fileType: "jpg",
- quality: 0.5,
- success: (res2) => exportSuccess(res2.tempFilePath),
- fail: (err2) => {
- console.warn("帧抓取:uni.canvasToTempFilePath 也失败", err2);
- this.isFrameCapturing = false;
- }
- }, this);
- }
- });
- } else {
- common_vendor.index.canvasToTempFilePath({
- canvas: hiddenCanvasNodeRef,
- x: 0,
- y: 0,
- width: frameW,
- height: frameH,
- destWidth: frameW,
- destHeight: frameH,
- fileType: "jpg",
- quality: 0.5,
- success: (res3) => exportSuccess(res3.tempFilePath),
- fail: (err3) => {
- console.warn("帧抓取:uni.canvasToTempFilePath 失败", err3);
- this.isFrameCapturing = false;
- }
- }, this);
- }
- };
- if (typeof canvas.requestAnimationFrame === "function") {
- canvas.requestAnimationFrame(() => doExport());
- } else {
- setTimeout(() => doExport(), 16);
- }
- } catch (err) {
- console.warn("帧抓取:绘制或导出异常", err);
- this.isFrameCapturing = false;
- }
- });
- if (listener && listener.start) {
- listener.start();
- console.info("帧抓取:监听已启动");
- }
- this.frameListener = listener;
- } catch (e) {
- console.warn("启动帧抓取监听失败,回退到拍照方案:", e);
- }
- },
- stopFrameStreamCapture() {
- try {
- if (this.frameListener && this.frameListener.stop) {
- this.frameListener.stop();
- }
- } catch (e) {
- }
- this.frameListener = null;
- },
- // ===== 追问次数控制:工具方法 =====
- getFollowUpLimit(jobPositionQuestionId) {
- if (!jobPositionQuestionId)
- return this.defaultFollowUpLimit;
- return this.followUpLimitMap[jobPositionQuestionId] || this.defaultFollowUpLimit;
- },
- setFollowUpLimit(jobPositionQuestionId, limit) {
- if (!jobPositionQuestionId)
- return;
- const parsed = parseInt(limit);
- this.followUpLimitMap[jobPositionQuestionId] = Number.isFinite(parsed) && parsed > 0 ? parsed : this.defaultFollowUpLimit;
- console.log(`设置问题 ${jobPositionQuestionId} 的追问上限为: ${this.followUpLimitMap[jobPositionQuestionId]}`);
- },
- resetFollowUpAskedCount(jobPositionQuestionId) {
- if (!jobPositionQuestionId)
- return;
- this.followUpAskedCountMap[jobPositionQuestionId] = 1;
- console.log(`重置问题 ${jobPositionQuestionId} 的追问次数为: 1`);
- },
- incrementFollowUpCount(jobPositionQuestionId) {
- if (!jobPositionQuestionId)
- return;
- const current = this.followUpAskedCountMap[jobPositionQuestionId] || 0;
- this.followUpAskedCountMap[jobPositionQuestionId] = current + 1;
- console.log(`问题 ${jobPositionQuestionId} 的追问次数增加到: ${this.followUpAskedCountMap[jobPositionQuestionId]}`);
- },
- canAskMoreFollowUps(jobPositionQuestionId) {
- if (!jobPositionQuestionId)
- return false;
- const asked = this.followUpAskedCountMap[jobPositionQuestionId] || 0;
- const limit = this.getFollowUpLimit(jobPositionQuestionId);
- const canAsk = asked < limit;
- console.log(`检查问题 ${jobPositionQuestionId} 是否可以继续追问: ${canAsk} (已问${asked}次/上限${limit}次)`);
- return canAsk;
- },
- async maybeRequestNextFollowUp(jobPositionQuestionId) {
- if (!jobPositionQuestionId) {
- console.log("缺少job_position_question_id,直接进入下一题");
- this.proceedToNextQuestion();
- return;
- }
- console.log(`检查是否需要继续追问,问题ID: ${jobPositionQuestionId}`);
- if (this.canAskMoreFollowUps(jobPositionQuestionId)) {
- if (this.followUpRequestInFlight[jobPositionQuestionId]) {
- console.log("已有追问请求进行中,跳过重复触发");
- return;
- }
- const ok = await this.callInterviewInteraction(jobPositionQuestionId);
- if (!ok) {
- console.log("未获取到下一条追问或调用失败,进入下一题");
- this.isFollowUpMode = false;
- this.isFollowUpQuestion = false;
- this.currentFollowUpQuestion = null;
- this.proceedToNextQuestion();
- }
- } else {
- console.log(`问题 ${jobPositionQuestionId} 追问次数已达上限,进入下一题`);
- this.isFollowUpMode = false;
- this.isFollowUpQuestion = false;
- this.currentFollowUpQuestion = null;
- this.proceedToNextQuestion();
- }
- },
- // 获取当前问题信息
- getCurrentQuestionByIndex(index) {
- return null;
- },
- // 处理音频播放完成
- handleAudioEnd() {
- console.log("音频播放完成");
- this.isWaitingForAnswer = true;
- this.showStartRecordingButton = true;
- setTimeout(() => {
- this.startCountdown();
- }, 100);
- },
- // 开始倒计时
- startCountdown() {
- this.showCountdown = true;
- this.countdownValue = 5;
- this.countdownTimer = setInterval(() => {
- this.countdownValue--;
- if (this.countdownValue <= 0) {
- this.clearCountdown();
- this.showStartRecordingButton = false;
- this.startRecordingAnswer();
- }
- }, 1e3);
- },
- // 清除倒计时
- clearCountdown() {
- if (this.countdownTimer) {
- clearInterval(this.countdownTimer);
- this.countdownTimer = null;
- }
- this.showCountdown = false;
- },
- // 处理追问问题
- async handleFollowUpQuestion(questionData) {
- console.log("处理追问:", questionData);
- this.enterFollowUpMode();
- console.log("处理追问问题数据:", questionData);
- if (!questionData || !questionData.follow_up_voice_url || !questionData.follow_up_question) {
- console.error("追问数据不完整:", questionData);
- common_vendor.index.showToast({
- title: "获取追问数据失败",
- icon: "none"
- });
- return;
- }
- this.parentQuestion = questionData.original_question || "";
- let audioUrl = "";
- if (questionData.follow_up_voice_url.direct_url) {
- audioUrl = questionData.follow_up_voice_url.direct_url;
- } else if (questionData.follow_up_voice_url.file_url) {
- audioUrl = questionData.follow_up_voice_url.file_url;
- }
- if (!audioUrl.startsWith("http")) {
- audioUrl = common_config.apiBaseUrl + audioUrl;
- }
- console.log("处理后的音频URL:", audioUrl);
- const followUpQuestionObj = {
- id: Date.now(),
- question: questionData.follow_up_question.trim(),
- // 去除可能的空白字符
- audioUrl,
- originalQuestion: questionData.original_question,
- sessionId: questionData.session_id
- };
- console.log("创建的追问问题对象:", followUpQuestionObj);
- this.followUpQuestions.push(followUpQuestionObj);
- this.currentFollowUpIndex = this.followUpQuestions.length - 1;
- this.followUpQuestion = followUpQuestionObj.question;
- this.followUpAudioUrl = followUpQuestionObj.audioUrl;
- this.isFollowUpQuestion = true;
- this.currentFollowUpQuestion = followUpQuestionObj;
- this.showSubtitle(followUpQuestionObj.question, true);
- try {
- await this.playFollowUpAudio();
- console.log("音频播放完成,准备录制回答");
- this.prepareToAnswer(true, followUpQuestionObj);
- } catch (error) {
- console.error("音频播放失败:", error);
- this.prepareToAnswer(true, followUpQuestionObj);
- }
- },
- // 准备回答问题
- prepareToAnswer(isFollowUp = false, questionData = null) {
- console.log("准备回答问题:", { isFollowUp, questionData });
- this.isRecording = false;
- this.recordedTime = 0;
- this.showStopRecordingButton = false;
- if (isFollowUp && questionData) {
- this.currentFollowUpQuestion = questionData;
- this.isFollowUpQuestion = true;
- }
- this.isWaitingForAnswer = true;
- this.handleAudioEnd();
- },
- // 调用面试互动接口
- async callInterviewInteraction(jobPositionQuestionId, retryCount = 0, maxRetries = 3) {
- const userInfo = JSON.parse(common_vendor.index.getStorageSync("userInfo"));
- const appId = common_vendor.index.getStorageSync("appId");
- const positionConfigId = JSON.parse(common_vendor.index.getStorageSync("configData")).id;
- try {
- this.showThinkingLoading();
- console.log("开始调用面试互动接口", { jobPositionQuestionId, appId });
- const res = await common_vendor.index.request({
- url: `${common_config.apiBaseUrl}/api/voice_interview_interaction/`,
- method: "POST",
- data: {
- tenant_id: common_vendor.index.getStorageSync("tenant_id") || userInfo.tenant_id || 1,
- question_id: jobPositionQuestionId,
- position_config_id: positionConfigId,
- application_id: appId
- },
- header: {
- "content-type": "application/json"
- }
- });
- console.log("面试互动接口返回数据:", res);
- if (res.statusCode === 400) {
- if (retryCount < maxRetries) {
- console.log(`视频转写未完成,${retryCount + 1}次重试中...`);
- await new Promise((resolve) => setTimeout(resolve, 3e3));
- return this.callInterviewInteraction(jobPositionQuestionId, retryCount + 1, maxRetries);
- } else {
- console.log("达到最大重试次数,视频转写仍未完成");
- common_vendor.index.showToast({
- title: "视频转写处理中,请稍后再试",
- icon: "none",
- duration: 2e3
- });
- return false;
- }
- }
- if (res.data.success) {
- if (jobPositionQuestionId) {
- this.incrementFollowUpCount(jobPositionQuestionId);
- }
- await this.handleFollowUpQuestion(res.data);
- this.hideThinkingLoading();
- return true;
- } else {
- console.error("面试互动接口返回错误:", res.data);
- this.hideThinkingLoading();
- return false;
- }
- } catch (error) {
- console.error("调用面试互动接口失败:", error);
- this.hideThinkingLoading();
- return false;
- }
- },
- // 播放追问音频
- async playFollowUpAudio() {
- return new Promise((resolve, reject) => {
- console.log("开始播放追问音频, URL:", this.followUpAudioUrl);
- if (!this.followUpAudioUrl) {
- console.error("没有音频URL");
- reject(new Error("没有音频URL"));
- return;
- }
- common_vendor.index.showLoading({
- title: "思考中..."
- });
- this.stopAndDestroyAudio();
- try {
- const innerAudioContext = common_vendor.index.createInnerAudioContext();
- this.audioContext = innerAudioContext;
- innerAudioContext.autoplay = true;
- innerAudioContext.obeyMuteSwitch = false;
- innerAudioContext.volume = 1;
- innerAudioContext.onCanplay(() => {
- console.log("音频可以播放");
- common_vendor.index.hideLoading();
- this.isAudioPlaying = true;
- });
- innerAudioContext.onEnded(() => {
- console.log("追问音频播放完成");
- this.isAudioPlaying = false;
- resolve();
- setTimeout(() => {
- this.stopAndDestroyAudio();
- this.prepareToAnswer(true, this.currentFollowUpQuestion);
- }, 100);
- });
- innerAudioContext.onError((res) => {
- console.error("音频播放错误:", res);
- this.isAudioPlaying = false;
- common_vendor.index.hideLoading();
- reject(res);
- this.stopAndDestroyAudio();
- });
- console.log("设置音频源:", this.followUpAudioUrl);
- innerAudioContext.src = this.followUpAudioUrl;
- } catch (error) {
- console.error("创建或播放音频失败:", error);
- this.isAudioPlaying = false;
- common_vendor.index.hideLoading();
- this.stopAndDestroyAudio();
- reject(error);
- }
- });
- },
- // 停止并销毁音频
- stopAndDestroyAudio() {
- if (!this.audioContext) {
- return;
- }
- const ctx = this.audioContext;
- this.audioContext = null;
- try {
- if (this.isAudioPlaying) {
- ctx.stop();
- }
- } catch (error) {
- console.error("停止音频播放失败:", error);
- }
- try {
- ctx.destroy();
- } catch (error) {
- console.error("销毁音频实例失败:", error);
- }
- this.isAudioPlaying = false;
- },
- // 绑定音频事件
- bindAudioEvents(audioContext, resolve, reject) {
- audioContext.onCanplay(() => {
- console.log("音频可以播放");
- });
- audioContext.onTimeUpdate(() => {
- console.log("音频播放进度:", audioContext.currentTime);
- });
- audioContext.onEnded(() => {
- console.log("追问音频播放完成");
- this.cleanupAudioContext();
- resolve();
- });
- audioContext.onError((res) => {
- console.error("音频播放错误:", res);
- this.cleanupAudioContext();
- reject(res);
- });
- },
- // 修改准备回答方法
- prepareToAnswer(isFollowUp = false, questionData = null) {
- this.isRecording = false;
- this.recordedTime = 0;
- this.showStopRecordingButton = false;
- if (isFollowUp && questionData) {
- this.currentFollowUpQuestion = questionData;
- this.isFollowUpQuestion = true;
- }
- this.isWaitingForAnswer = true;
- this.handleAudioEnd();
- },
- // 初始化相机
- async initCamera() {
- const systemInfo = common_vendor.index.getSystemInfoSync();
- const isMiniProgram = systemInfo.uniPlatform === "mp-weixin" || systemInfo.uniPlatform === "mp-alipay" || systemInfo.uniPlatform === "mp-baidu";
- if (isMiniProgram) {
- this.useMiniProgramCameraComponent = true;
- this.cameraContext = common_vendor.index.createCameraContext();
- common_vendor.index.getSetting({
- success: (res) => {
- if (!res.authSetting["scope.record"]) {
- common_vendor.index.authorize({
- scope: "scope.record",
- success: () => {
- console.log("录音权限已获取");
- },
- fail: (err) => {
- console.error("录音权限获取失败:", err);
- this.showPermissionDialog("录音");
- }
- });
- }
- if (!res.authSetting["scope.camera"]) {
- common_vendor.index.authorize({
- scope: "scope.camera",
- success: () => {
- console.log("相机权限已获取");
- },
- fail: (err) => {
- console.error("相机权限获取失败:", err);
- this.showPermissionDialog("相机");
- }
- });
- }
- const systemInfo2 = common_vendor.index.getSystemInfoSync();
- if (systemInfo2.platform === "ios") {
- if (!res.authSetting["scope.camera"] || !res.authSetting["scope.record"]) {
- console.log("iOS需要同时获取相机和录音权限");
- }
- }
- }
- });
- } else {
- try {
- const constraints = {
- audio: {
- echoCancellation: true,
- noiseSuppression: true,
- autoGainControl: true
- },
- video: {
- width: { ideal: 640, max: 1280 },
- // 控制视频宽度
- height: { ideal: 480, max: 720 },
- // 控制视频高度
- frameRate: { ideal: 15, max: 24 },
- // 控制帧率
- facingMode: "user"
- }
- };
- const stream = await navigator.mediaDevices.getUserMedia(constraints);
- this.cameraStream = stream;
- const audioTracks = stream.getAudioTracks();
- console.log("音频轨道数量:", audioTracks.length);
- if (audioTracks.length > 0) {
- console.log("音频轨道已获取:", audioTracks[0].label);
- audioTracks[0].enabled = true;
- } else {
- console.warn("未检测到音频轨道,尝试单独获取音频");
- this.tryGetAudioOnly();
- }
- const videoElement = this.$refs.userCameraVideo;
- if (videoElement) {
- videoElement.srcObject = stream;
- videoElement.muted = true;
- }
- } catch (error) {
- console.error("获取摄像头失败:", error);
- this.cameraError = error.message || "无法访问摄像头";
- common_vendor.index.showToast({
- title: "无法访问摄像头,请检查权限设置",
- icon: "none"
- });
- }
- }
- },
- // 停止用户摄像头
- stopUserCamera() {
- if (this.cameraStream) {
- this.cameraStream.getTracks().forEach((track) => {
- track.stop();
- });
- this.cameraStream = null;
- }
- },
- async fetchData() {
- this.loading = true;
- this.assistantResponse = "";
- this.audioTranscript = "";
- this.processedResponses = [];
- common_vendor.index.showLoading({
- title: "面试官思考中...",
- mask: true
- // 添加遮罩,防止用户触摸界面
- });
- try {
- const requestTask = common_vendor.index.request({
- url: "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions",
- method: "POST",
- header: {
- "Content-Type": "application/json",
- "Authorization": "Bearer sk-9e1ec73a7d97493b8613c63f06b6110c"
- },
- data: {
- "model": "qwen-omni-turbo",
- "messages": [
- {
- "role": "user",
- "content": [
- {
- "type": "input_audio",
- "input_audio": {
- "data": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250211/tixcef/cherry.wav",
- "format": "wav"
- }
- },
- {
- "type": "text",
- "text": "这段音频在说什么"
- }
- ]
- }
- ],
- "stream": true,
- "stream_options": {
- "include_usage": true
- },
- "modalities": ["text", "audio"],
- "audio": { "voice": "Cherry", "format": "wav" }
- },
- success: (res) => {
- console.log("请求成功,响应数据:", res.data);
- if (typeof res.data === "string" && res.data.includes("data: {")) {
- const chunks = res.data.split("data: ").filter((chunk) => chunk.trim() !== "");
- chunks.forEach((chunk) => {
- this.handleStreamResponse(chunk);
- });
- } else {
- this.handleStreamResponse(res.data);
- }
- this.playDigitalHumanVideo();
- },
- fail: (err) => {
- console.error("请求失败:", err);
- common_vendor.index.showToast({
- title: "请求失败,请重试",
- icon: "none"
- });
- },
- complete: () => {
- this.loading = false;
- common_vendor.index.hideLoading();
- }
- });
- } catch (error) {
- console.error("获取数据失败:", error);
- this.loading = false;
- common_vendor.index.hideLoading();
- common_vendor.index.showToast({
- title: "系统错误,请重试",
- icon: "none"
- });
- }
- },
- handleStreamResponse(data) {
- if (typeof data === "string") {
- if (data === "[DONE]")
- return;
- try {
- const cleanData = data.trim();
- if (cleanData.startsWith("{") && cleanData.endsWith("}")) {
- const jsonData = JSON.parse(cleanData);
- this.processStreamChunk(jsonData);
- }
- } catch (e) {
- console.error("解析JSON失败:", e, "原始数据:", data);
- }
- } else {
- this.processStreamChunk(data);
- }
- },
- processStreamChunk(chunk) {
- if (chunk.choices && chunk.choices.length > 0) {
- const choice = chunk.choices[0];
- if (choice.delta && choice.delta.content) {
- this.assistantResponse += choice.delta.content;
- }
- if (choice.delta && choice.delta.audio && choice.delta.audio.transcript) {
- this.audioTranscript += choice.delta.audio.transcript;
- }
- if (choice.delta) {
- const result = {};
- if (choice.delta.role) {
- result.role = choice.delta.role;
- }
- if (choice.delta.audio && choice.delta.audio.transcript) {
- result.transcript = choice.delta.audio.transcript;
- }
- if (Object.keys(result).length > 0) {
- this.processedResponses.push(result);
- }
- }
- }
- },
- processResponseData() {
- this.processedResponses = this.responses.map((item) => {
- const result = {};
- if (item.delta && item.delta.role) {
- result.role = item.delta.role;
- }
- if (item.delta && item.delta.audio && item.delta.audio.transcript) {
- result.transcript = item.delta.audio.transcript;
- }
- return result;
- }).filter((item) => Object.keys(item).length > 0);
- },
- // 播放数字人视频
- playDigitalHumanVideo() {
- if (this.videoList.length === 0) {
- this.fetchQuestions();
- return;
- }
- this.videoUrl = this.videoList[this.currentVideoIndex];
- this.videoPlaying = true;
- this.$nextTick(() => {
- const videoContext = common_vendor.index.createVideoContext("myVideo", this);
- if (videoContext) {
- videoContext.play();
- setTimeout(() => {
- if (this.videoPlaying && this.$refs.videoPlayer) {
- console.log("视频应该正在播放");
- } else {
- console.log("视频可能未成功播放,尝试替代方案");
- this.tryAlternativeVideoPath();
- }
- }, 1e3);
- } else {
- console.error("无法创建视频上下文");
- this.tryAlternativeVideoPath();
- }
- });
- },
- // 修改 tryAlternativeVideoPath 方法
- tryAlternativeVideoPath() {
- console.log("尝试使用替代路径");
- const alternativePaths = [
- "./static/demo.mp4",
- "../static/demo.mp4",
- "static/demo.mp4",
- "/static/demo.mp4",
- // 添加绝对路径
- `${window.location.origin}/static/demo.mp4`
- ];
- const currentPathIndex = alternativePaths.indexOf(this.videoUrl);
- const nextPathIndex = (currentPathIndex + 1) % alternativePaths.length;
- this.videoUrl = alternativePaths[nextPathIndex];
- console.log("尝试新路径:", this.videoUrl);
- this.$nextTick(() => {
- const videoContext = common_vendor.index.createVideoContext("myVideo", this);
- if (videoContext) {
- videoContext.stop();
- videoContext.play();
- setTimeout(() => {
- if (nextPathIndex === alternativePaths.length - 1 && !this.videoPlaying) {
- console.log("所有路径均失败,尝试使用uni.getVideoInfo检查视频");
- this.checkVideoWithAPI();
- }
- }, 1e3);
- }
- });
- },
- // 添加新方法:使用uni API检查视频
- checkVideoWithAPI() {
- common_vendor.index.getVideoInfo({
- src: "/static/demo.mp4",
- success: (res) => {
- console.log("视频信息获取成功:", res);
- this.videoUrl = "/static/demo.mp4";
- this.$nextTick(() => {
- const videoContext = common_vendor.index.createVideoContext("myVideo", this);
- if (videoContext) {
- videoContext.play();
- }
- });
- },
- fail: (err) => {
- console.error("视频信息获取失败:", err);
- this.fallbackToLocalVideo();
- }
- });
- },
- // 添加新方法:回退到本地视频
- fallbackToLocalVideo() {
- console.log("尝试使用本地视频资源");
- const platform = common_vendor.index.getSystemInfoSync().platform;
- if (platform === "android" || platform === "ios") {
- this.videoUrl = platform === "android" ? "android.resource://package_name/raw/demo" : "file:///assets/demo.mp4";
- this.$nextTick(() => {
- const videoContext = common_vendor.index.createVideoContext("myVideo", this);
- if (videoContext) {
- videoContext.play();
- }
- });
- } else {
- this.videoPlaying = false;
- common_vendor.index.showToast({
- title: "视频加载失败,显示静态图片",
- icon: "none"
- });
- }
- },
- // 修改 handleVideoError 方法
- handleVideoError(e) {
- console.error("视频加载错误:", e);
- if (e && e.detail) {
- console.error("详细错误信息:", e.detail);
- }
- common_vendor.index.getFileInfo({
- filePath: this.videoUrl.startsWith("/") ? this.videoUrl.substring(1) : this.videoUrl,
- success: (res) => {
- console.log("文件存在,大小:", res.size);
- this.tryDifferentFormat();
- },
- fail: (err) => {
- console.error("文件不存在或无法访问:", err);
- this.tryAlternativeVideoPath();
- }
- });
- common_vendor.index.showToast({
- title: "视频加载失败,请检查文件是否存在",
- icon: "none",
- duration: 2e3
- });
- },
- // 添加新方法:尝试不同格式
- tryDifferentFormat() {
- console.log("尝试不同的视频格式");
- const formats = [
- { ext: "mp4", mime: "video/mp4" },
- { ext: "webm", mime: "video/webm" },
- { ext: "ogg", mime: "video/ogg" },
- { ext: "mov", mime: "video/quicktime" }
- ];
- const currentPath = this.videoUrl;
- const basePath = currentPath.substring(0, currentPath.lastIndexOf(".")) || "/static/demo";
- let nextFormat = formats.find((f) => !currentPath.endsWith(f.ext));
- if (nextFormat) {
- this.videoUrl = `${basePath}.${nextFormat.ext}`;
- console.log("尝试新格式:", this.videoUrl);
- this.$nextTick(() => {
- const videoContext = common_vendor.index.createVideoContext("myVideo", this);
- if (videoContext) {
- videoContext.stop();
- videoContext.play();
- }
- });
- } else {
- this.useBuiltInResource();
- }
- },
- // 添加新方法:使用内置资源
- useBuiltInResource() {
- console.log("尝试使用内置资源");
- const platform = common_vendor.index.getSystemInfoSync().platform;
- if (platform === "windows") {
- process.env.UNI_INPUT_DIR || "";
- this.videoUrl = `./static/demo.mp4`;
- console.log("Windows平台尝试路径:", this.videoUrl);
- } else if (platform === "android" || platform === "ios") {
- this.useNativeVideo();
- } else {
- const baseUrl = window.location.origin;
- this.videoUrl = `${baseUrl}/static/demo.mp4`;
- console.log("Web平台尝试URL:", this.videoUrl);
- }
- this.$nextTick(() => {
- const videoContext = common_vendor.index.createVideoContext("myVideo", this);
- if (videoContext) {
- videoContext.play();
- }
- });
- },
- // 添加新方法:使用原生视频能力
- useNativeVideo() {
- console.log("尝试使用原生视频能力");
- common_vendor.index.chooseVideo({
- sourceType: ["album"],
- success: (res) => {
- this.videoUrl = res.tempFilePath;
- this.$nextTick(() => {
- const videoContext = common_vendor.index.createVideoContext("myVideo", this);
- if (videoContext) {
- videoContext.play();
- }
- });
- },
- fail: () => {
- this.videoPlaying = false;
- }
- });
- },
- // 处理视频结束事件
- handleVideoEnded() {
- console.log("视频播放结束事件触发");
- const videoElement = this.$refs.videoPlayer;
- if (videoElement) {
- const currentTime = videoElement.currentTime || 0;
- const duration = videoElement.duration || 0;
- if (duration > 0 && duration - currentTime > 0.5) {
- console.log("检测到可能的误触发结束事件,继续播放", currentTime, duration);
- setTimeout(() => {
- const videoContext = common_vendor.index.createVideoContext("myVideo", this);
- if (videoContext) {
- if (duration - currentTime > 2) {
- videoContext.seek(this.historyTime || 0);
- } else {
- videoContext.play();
- }
- }
- }, 100);
- return;
- }
- console.log("视频确认结束,当前时间:", currentTime, "总时长:", duration);
- }
- this.videoPlaying = false;
- if (this.isPlayingLowScoreVideo) {
- console.log("低分提示视频播放完成");
- if (this.retryCount < this.maxRetryAttempts) {
- console.log(`显示重新录制按钮 (重试次数: ${this.retryCount + 1}/${this.maxRetryAttempts})`);
- this.showRerecordButton = true;
- if (this.isFollowUpQuestion && this.currentFollowUpQuestion) {
- this.currentSubtitle = this.currentFollowUpQuestion.question || this.currentFollowUpQuestion.question;
- } else if (this.originalQuestionSubtitle) {
- this.currentSubtitle = this.originalQuestionSubtitle;
- }
- } else {
- console.log("已达到最大重试次数,继续下一题");
- this.retryCount = 0;
- this.proceedToNextQuestion();
- }
- this.isPlayingLowScoreVideo = false;
- this.originalQuestionSubtitle = null;
- return;
- }
- if (this.isFollowUpQuestion) {
- console.log("追问问题视频播放完成");
- this.showStartRecordingButton = true;
- this.startCountdown();
- return;
- }
- if (this.currentVideoIndex >= 1) {
- this.showStartRecordingButton = true;
- this.startCountdown();
- } else {
- this.showAnswerButton = true;
- }
- if (this.isFollowUpQuestion) {
- this.isFollowUpQuestion = false;
- this.currentFollowUpQuestion = null;
- }
- },
- // 添加新方法:开始倒计时
- startCountdown() {
- this.clearCountdown();
- this.showCountdown = true;
- this.countdownValue = 10;
- this.countdownTimer = setInterval(() => {
- if (!this.showStartRecordingButton) {
- this.clearCountdown();
- return;
- }
- this.countdownValue--;
- if (this.countdownValue <= 0) {
- this.clearCountdown();
- this.showStartRecordingButton = false;
- this.startRecordingAnswer();
- }
- }, 1e3);
- },
- // 添加新方法:清除倒计时
- clearCountdown() {
- if (this.countdownTimer) {
- clearInterval(this.countdownTimer);
- this.countdownTimer = null;
- }
- this.showCountdown = false;
- },
- // 修改 handleStartRecordingClick 方法,使其可以终止倒计时
- handleStartRecordingClick() {
- this.showStartRecordingButton = false;
- this.clearCountdown();
- this.isWaitingForAnswer = false;
- this.startRecordingAnswer();
- },
- // 修改 stopRecordingAnswer 方法,添加录制时长检查
- stopRecordingAnswer() {
- this.clearCountdown();
- this.isWaitingForAnswer = false;
- const recordingDuration = this.getRecordingDuration();
- const minimumDuration = 3;
- const lowScoreDuration = 7;
- this.currentRecordingDuration = recordingDuration;
- if (recordingDuration < minimumDuration) {
- common_vendor.index.showToast({
- title: "录制时间过短,请至少录制3秒",
- icon: "none",
- duration: 2e3
- });
- return;
- }
- if (recordingDuration < lowScoreDuration) {
- console.log(`录制时间 ${recordingDuration} 秒,少于 ${lowScoreDuration} 秒,将播放低分提示视频`);
- this.completeRecordingStop(false);
- this.playLowScoreVideo();
- } else {
- this.completeRecordingStop(true);
- this.needPlayLowScoreVideo = false;
- this.recordingTimeDisplay = "00:00";
- }
- },
- // 添加新方法:开始录制用户回答
- startRecordingAnswer() {
- console.log("开始录制用户回答");
- this.isRecording = true;
- this.lastFrameCaptureAt = 0;
- try {
- if (this.personDetectionSocket && this.personDetectionSocket.readyState === 1) {
- if (!this.hiddenCanvasReady) {
- this.initHiddenCanvasNode(false, 3);
- }
- this.startFrameStreamCapture();
- }
- } catch (e) {
- }
- this.recordingStartTime = Date.now();
- this.recordingTimerCount = 0;
- this.maxRecordingTime = this.getCurrentQuestionRecommendedDuration();
- this.remainingTime = this.maxRecordingTime;
- this.recordingTimer = setInterval(() => {
- this.recordingTimerCount++;
- this.remainingTime = Math.max(0, this.maxRecordingTime - this.recordingTimerCount);
- this.recordingTimeDisplay = this.formatTime(this.recordingTimerCount);
- this.progressPercent = Math.min(this.recordingTimerCount / this.maxRecordingTime * 100, 100);
- if (this.recordingTimerCount >= this.maxRecordingTime) {
- console.log(`已达到最大录制时间(${this.maxRecordingTime}秒),自动停止录制`);
- this.stopRecordingAnswer();
- }
- }, 1e3);
- const systemInfo = common_vendor.index.getSystemInfoSync();
- const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith("mp-");
- if (isMiniProgram) {
- this.startMiniProgramRecording();
- } else {
- this.startBrowserRecording();
- }
- this.showStopRecordingButton = true;
- },
- // 添加一个新方法:重置相机组件
- resetCamera() {
- console.log("重置相机组件");
- this.useMiniProgramCameraComponent = false;
- if (this.cameraContext) {
- this.cameraContext = null;
- }
- setTimeout(() => {
- this.useMiniProgramCameraComponent = true;
- setTimeout(() => {
- this.cameraContext = common_vendor.index.createCameraContext();
- console.log("相机组件已重置");
- }, 500);
- }, 500);
- },
- // 修改 startMiniProgramRecording 方法
- startMiniProgramRecording() {
- console.log("开始小程序录制方法");
- const systemInfo = common_vendor.index.getSystemInfoSync();
- const isIOS = systemInfo.platform === "ios";
- if (isIOS) {
- this.resetCamera();
- setTimeout(() => {
- this.actualStartRecording(isIOS);
- }, 1e3);
- } else {
- this.actualStartRecording(isIOS);
- }
- },
- // 添加新方法:实际开始录制
- actualStartRecording(isIOS) {
- if (!this.cameraContext) {
- this.cameraContext = common_vendor.index.createCameraContext();
- console.log("创建新的相机上下文");
- }
- common_vendor.index.getSetting({
- success: (res) => {
- const hasRecordAuth = res.authSetting["scope.record"];
- const hasCameraAuth = res.authSetting["scope.camera"];
- if (!hasRecordAuth || !hasCameraAuth) {
- console.warn("缺少必要权限,请求权限");
- this.requestMiniProgramPermissions();
- return;
- }
- if (isIOS) {
- console.log("iOS: 检查相机状态");
- const maxDuration = this.getCurrentQuestionRecommendedDuration() * 1e3;
- const options = {
- timeout: maxDuration,
- // 使用当前问题的推荐时长
- quality: "low",
- // 降低质量
- compressed: true,
- success: () => {
- console.log("iOS录制开始成功");
- },
- fail: (err) => {
- console.error("iOS录制失败:", err);
- this.useAlternativeRecordingMethod();
- }
- };
- try {
- console.log("尝试开始录制");
- this.recorder = this.cameraContext.startRecord(options);
- } catch (e) {
- console.error("开始录制异常:", e);
- this.useAlternativeRecordingMethod();
- }
- } else {
- const maxDuration = this.getCurrentQuestionRecommendedDuration() * 1e3;
- const options = {
- timeout: maxDuration,
- // 使用当前问题的推荐时长
- quality: "medium",
- compressed: true,
- success: () => {
- console.log("Android录制开始成功");
- },
- fail: (err) => {
- console.error("Android录制失败:", err);
- common_vendor.index.showToast({
- title: "录制失败,请检查相机权限",
- icon: "none"
- });
- this.proceedToNextQuestion();
- }
- };
- this.recorder = this.cameraContext.startRecord(options);
- }
- }
- });
- },
- // 添加新方法:使用替代录制方法
- useAlternativeRecordingMethod() {
- console.log("使用替代录制方法");
- common_vendor.index.showActionSheet({
- itemList: ["使用相册中的视频", "跳过此问题"],
- success: (res) => {
- if (res.tapIndex === 0) {
- common_vendor.index.chooseVideo({
- sourceType: ["album"],
- maxDuration: this.getCurrentQuestionRecommendedDuration(),
- // 使用当前问题的推荐时长
- camera: "front",
- success: (res2) => {
- console.log("选择视频成功:", res2.tempFilePath);
- this.isRecording = false;
- this.showStopRecordingButton = false;
- this.uploadRecordedVideo(res2.tempFilePath);
- },
- fail: () => {
- console.log("用户取消选择视频");
- this.proceedToNextQuestion();
- }
- });
- } else {
- console.log("用户选择跳过问题");
- this.proceedToNextQuestion();
- }
- },
- fail: () => {
- console.log("操作取消");
- this.proceedToNextQuestion();
- }
- });
- },
- // 添加新方法:请求小程序权限
- requestMiniProgramPermissions() {
- common_vendor.index.authorize({
- scope: "scope.record",
- success: () => {
- console.log("录音权限已获取");
- common_vendor.index.authorize({
- scope: "scope.camera",
- success: () => {
- console.log("相机权限已获取");
- this.startMiniProgramRecording();
- },
- fail: (err) => {
- console.error("相机权限获取失败:", err);
- this.showPermissionDialog("相机");
- }
- });
- },
- fail: (err) => {
- console.error("录音权限获取失败:", err);
- this.showPermissionDialog("录音");
- }
- });
- },
- // 修改浏览器环境下的录制方法
- startBrowserRecording() {
- if (!this.cameraStream) {
- console.error("没有可用的摄像头流");
- this.proceedToNextQuestion();
- return;
- }
- try {
- const hasAudio = this.cameraStream.getAudioTracks().length > 0;
- if (!hasAudio) {
- console.warn("警告:媒体流中没有音频轨道,尝试重新获取带音频的媒体流");
- navigator.mediaDevices.getUserMedia({
- audio: {
- echoCancellation: true,
- noiseSuppression: true,
- autoGainControl: true
- },
- video: true
- }).then((newStream) => {
- const audioTracks = newStream.getAudioTracks();
- if (audioTracks.length > 0) {
- console.log("成功获取音频轨道:", audioTracks[0].label);
- const videoTrack = this.cameraStream.getVideoTracks()[0];
- const audioTrack = newStream.getAudioTracks()[0];
- const combinedStream = new MediaStream();
- if (videoTrack)
- combinedStream.addTrack(videoTrack);
- if (audioTrack)
- combinedStream.addTrack(audioTrack);
- this.cameraStream = combinedStream;
- const videoElement = this.$refs.userCameraVideo;
- if (videoElement) {
- videoElement.srcObject = combinedStream;
- videoElement.muted = true;
- }
- this.setupMediaRecorder(combinedStream);
- } else {
- console.warn("仍然无法获取音频轨道");
- this.setupMediaRecorder(this.cameraStream);
- }
- }).catch((err) => {
- console.error("获取音频失败:", err);
- this.setupMediaRecorder(this.cameraStream);
- });
- } else {
- console.log("检测到音频轨道,直接使用");
- this.setupMediaRecorder(this.cameraStream);
- }
- } catch (error) {
- console.error("浏览器录制失败:", error);
- common_vendor.index.showToast({
- title: "录制失败,浏览器可能不支持此功能",
- icon: "none"
- });
- this.proceedToNextQuestion();
- }
- },
- // 修改 setupMediaRecorder 方法
- setupMediaRecorder(stream) {
- const videoTracks = stream.getVideoTracks();
- const audioTracks = stream.getAudioTracks();
- console.log("设置MediaRecorder - 视频轨道:", videoTracks.length, "音频轨道:", audioTracks.length);
- let mimeType = "";
- const supportedTypes = [
- "video/webm;codecs=vp9,opus",
- "video/webm;codecs=vp8,opus",
- "video/webm;codecs=h264,opus",
- "video/mp4;codecs=h264,aac",
- "video/webm",
- "video/mp4"
- ];
- for (const type of supportedTypes) {
- if (MediaRecorder.isTypeSupported(type)) {
- mimeType = type;
- console.log("使用支持的MIME类型:", mimeType);
- break;
- }
- }
- const options = {
- mimeType: mimeType || "",
- audioBitsPerSecond: 64e3,
- // 降低音频比特率
- videoBitsPerSecond: 1e6
- // 降低视频比特率到1Mbps
- };
- try {
- this.mediaRecorder = new MediaRecorder(stream, options);
- console.log("MediaRecorder创建成功,使用选项:", options);
- } catch (e) {
- console.warn("使用指定选项创建MediaRecorder失败,尝试使用默认选项");
- this.mediaRecorder = new MediaRecorder(stream);
- }
- this.recordedChunks = [];
- this.mediaRecorder.ondataavailable = (event) => {
- if (event.data && event.data.size > 0) {
- this.recordedChunks.push(event.data);
- console.log(`收到数据块: ${event.data.size} 字节`);
- }
- };
- this.mediaRecorder.onstop = async () => {
- console.log("MediaRecorder停止,数据块数量:", this.recordedChunks.length);
- if (this.recordedChunks.length === 0) {
- console.error("没有录制到数据");
- this.proceedToNextQuestion();
- return;
- }
- const mimeType2 = this.mediaRecorder.mimeType || "video/webm";
- const blob = new Blob(this.recordedChunks, { type: mimeType2 });
- console.log("创建Blob,原始大小:", blob.size, "类型:", mimeType2);
- common_vendor.index.showLoading({
- title: "正在处理视频...",
- mask: true
- });
- try {
- const compressedBlob = await this.compressVideo(blob);
- const fileName = `answer_${this.currentVideoIndex}_${Date.now()}.webm`;
- const file = new File([compressedBlob], fileName, { type: mimeType2 });
- common_vendor.index.hideLoading();
- this.uploadRecordedVideo(file);
- } catch (error) {
- console.error("视频处理失败:", error);
- common_vendor.index.hideLoading();
- const fileName = `answer_${this.currentVideoIndex}_${Date.now()}.webm`;
- const file = new File([blob], fileName, { type: mimeType2 });
- this.uploadRecordedVideo(file);
- }
- };
- this.mediaRecorder.onerror = (event) => {
- console.error("MediaRecorder错误:", event.error);
- };
- try {
- this.mediaRecorder.start(1e3);
- console.log("MediaRecorder开始录制");
- this.mediaRecorderTimeout = setTimeout(() => {
- if (this.mediaRecorder && this.mediaRecorder.state === "recording") {
- console.log("MediaRecorder备份超时机制触发,停止录制");
- this.mediaRecorder.stop();
- }
- }, 3e5);
- } catch (e) {
- console.error("开始录制失败:", e);
- }
- },
- // 添加新方法:获取录制时长
- getRecordingDuration() {
- if (this.recordingStartTime) {
- return (Date.now() - this.recordingStartTime) / 1e3;
- }
- if (this.mediaRecorder && this.$refs.userCameraVideo) {
- return this.$refs.userCameraVideo.currentTime || 0;
- }
- if (this.recordingTimerCount) {
- return this.recordingTimerCount;
- }
- return 0;
- },
- // 添加新方法:重置录制
- resetRecording() {
- if (this.recordingTimer) {
- clearTimeout(this.recordingTimer);
- }
- this.recordingStartTime = Date.now();
- this.recordingTimerCount = 0;
- if (this.mediaRecorder && this.mediaRecorder.state !== "inactive") {
- this.mediaRecorder.stop();
- this.recordedChunks = [];
- setTimeout(() => {
- this.startBrowserRecording();
- }, 500);
- } else if (this.cameraContext) {
- this.cameraContext.stopRecord({
- success: () => {
- console.log("相机录制已停止");
- },
- fail: (err) => {
- console.error("停止相机录制失败:", err);
- }
- });
- }
- },
- // 修改 completeRecordingStop 方法,确保正确处理追问问题ID
- completeRecordingStop(uploadVideo = true) {
- console.log("完成录制停止");
- if (this.recordingTimer) {
- clearInterval(this.recordingTimer);
- this.recordingTimer = null;
- }
- this.finalRecordingDuration = this.recordingTimerCount;
- this.showStopRecordingButton = false;
- this.isRecording = false;
- this.stopFrameStreamCapture();
- const systemInfo = common_vendor.index.getSystemInfoSync();
- const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith("mp-");
- if (isMiniProgram) {
- if (uploadVideo) {
- this.stopMiniProgramRecording();
- } else {
- if (this.cameraContext) {
- this.cameraContext.stopRecord({
- success: () => {
- console.log("相机录制已停止,不上传视频");
- },
- fail: (err) => {
- console.error("停止相机录制失败:", err);
- }
- });
- }
- }
- } else {
- if (uploadVideo) {
- this.stopBrowserRecording();
- } else {
- if (this.mediaRecorder && this.mediaRecorder.state !== "inactive") {
- this.mediaRecorder.stop();
- this.recordedChunks = [];
- }
- }
- }
- if (this.isFollowUpQuestion && this.currentFollowUpQuestion) {
- console.log("当前是追问问题,记录追问问题ID:", this.currentFollowUpQuestion.id);
- this.lastQuestionWasFollowUp = true;
- this.lastFollowUpQuestionId = this.currentFollowUpQuestion.id;
- } else {
- this.lastQuestionWasFollowUp = false;
- this.lastFollowUpQuestionId = null;
- }
- },
- // 修改 stopMiniProgramRecording 方法,确保正确传递追问问题ID
- stopMiniProgramRecording() {
- console.log("停止小程序录制");
- if (!this.cameraContext) {
- console.error("相机上下文不存在");
- this.proceedToNextQuestion();
- return;
- }
- this.cameraContext.stopRecord({
- success: async (res) => {
- console.log("小程序录制停止成功:", res);
- const videoPath = res.tempVideoPath;
- if (videoPath) {
- await this.uploadRecordedVideo(videoPath);
- } else {
- console.error("未获取到录制视频路径");
- this.proceedToNextQuestion();
- }
- },
- fail: (err) => {
- console.error("小程序录制停止失败:", err);
- this.proceedToNextQuestion();
- }
- });
- },
- // 添加新方法:停止浏览器录制
- stopBrowserRecording() {
- if (this.mediaRecorder && this.mediaRecorder.state !== "inactive") {
- this.mediaRecorder.stop();
- console.log("浏览器录制停止成功");
- } else {
- console.error("MediaRecorder不存在或已经停止");
- this.proceedToNextQuestion();
- }
- },
- // 修改 uploadRecordedVideo 方法,添加记录父问题ID的逻辑
- uploadRecordedVideo(fileOrPath) {
- console.log("准备上传视频:", typeof fileOrPath === "string" ? fileOrPath : fileOrPath.name);
- console.log("当前问题ID:", this.currentParentQuestionId);
- console.log("当前问题类型:", this.isFollowUpQuestion);
- console.log("当前追问问题:", this.currentFollowUpQuestion);
- let questionId;
- let isFollowUpQuestionUpload = false;
- let questionText = "";
- let questionForm = 0;
- if (this.currentFollowUpQuestion && (this.currentFollowUpQuestion.question_form === 5 || this.isFollowUpQuestion)) {
- questionId = this.currentFollowUpQuestion.id;
- isFollowUpQuestionUpload = true;
- questionText = this.currentFollowUpQuestion.question || "";
- questionForm = 5;
- console.log("正在上传追问问题的回答:", {
- questionId,
- questionText,
- questionForm,
- isFollowUp: true
- });
- } else {
- this.showThinkingLoading();
- const currentQuestion = this.getCurrentQuestionByIndex(this.currentVideoIndex);
- if (currentQuestion && currentQuestion.id) {
- questionId = currentQuestion.id;
- questionText = currentQuestion.question || "";
- console.log("正在上传常规问题的回答:", {
- questionId,
- questionText,
- questionForm: 0
- });
- } else {
- questionId = this.getDefaultQuestionId(this.currentVideoIndex);
- console.log("使用默认问题ID:", questionId);
- }
- }
- const uploadTask = {
- id: Date.now().toString(),
- file: fileOrPath,
- questionId,
- isFollowUp: isFollowUpQuestionUpload,
- questionText,
- questionForm,
- attempts: 0,
- maxAttempts: 3,
- parentQuestionId: this.currentParentQuestionId,
- videoDuration: this.currentRecordingDuration || 0
- // 添加视频时长
- };
- if (!isFollowUpQuestionUpload) {
- this.currentParentQuestionId = questionId;
- }
- this.uploadQueue.push(uploadTask);
- this.uploadProgress[uploadTask.id] = 0;
- this.uploadStatus[uploadTask.id] = "pending";
- this.updateUploadStatusText();
- if (isFollowUpQuestionUpload) {
- console.log("追问问题使用后台上传,不阻塞流程");
- this.handlePostUploadActions(uploadTask);
- this.startBackgroundUpload(uploadTask);
- return Promise.resolve();
- } else {
- return new Promise((resolve) => {
- const checkUploadStatus = () => {
- if (!this.isUploading && this.uploadQueue.length === 0) {
- this.handlePostUploadActions(uploadTask);
- resolve();
- } else {
- setTimeout(checkUploadStatus, 100);
- }
- };
- if (!this.isUploading) {
- this.processUploadQueue();
- }
- checkUploadStatus();
- });
- }
- },
- // 添加新方法:启动后台上传
- startBackgroundUpload(task) {
- console.log("启动后台上传任务:", task.id);
- task.isBackgroundUpload = true;
- const taskIndex = this.uploadQueue.findIndex((t) => t.id === task.id);
- if (taskIndex !== -1) {
- this.uploadQueue.splice(taskIndex, 1);
- }
- if (!this.backgroundUploadQueue) {
- this.backgroundUploadQueue = [];
- }
- this.backgroundUploadQueue.push(task);
- this.processBackgroundUploadQueue();
- },
- // 添加新方法:处理后台上传队列
- processBackgroundUploadQueue() {
- if (!this.backgroundUploadQueue || this.backgroundUploadQueue.length === 0) {
- return;
- }
- const task = this.backgroundUploadQueue[0];
- console.log("开始后台上传:", task.id);
- this.uploadStatus[task.id] = "uploading";
- this.updateUploadStatusText();
- task.attempts++;
- if (typeof task.file === "string") {
- this.uploadFileWithUniBackground(task);
- } else {
- this.uploadFileWithXHRBackground(task);
- }
- },
- // 添加新方法:使用XMLHttpRequest后台上传文件
- uploadFileWithXHRBackground(task) {
- const userInfo = common_vendor.index.getStorageSync("userInfo");
- const openid = userInfo ? JSON.parse(userInfo).openid || "" : "";
- const tenant_id = common_vendor.index.getStorageSync("tenant_id") || JSON.parse(common_vendor.index.getStorageSync("userInfo")).tenant_id || "1";
- const formData = new FormData();
- formData.append("file", task.file);
- formData.append("openid", openid);
- formData.append("tenant_id", tenant_id);
- formData.append("application_id", common_vendor.index.getStorageSync("appId"));
- formData.append("question_id", task.questionId);
- formData.append("video_duration", task.videoDuration || 0);
- formData.append("has_audio", "true");
- const xhr = new XMLHttpRequest();
- xhr.upload.onprogress = (event) => {
- if (event.lengthComputable) {
- const progress = Math.round(event.loaded / event.total * 100);
- this.uploadProgress[task.id] = progress;
- this.updateUploadStatusText();
- }
- };
- xhr.onload = () => {
- if (xhr.status === 200) {
- try {
- const res = JSON.parse(xhr.responseText);
- console.log("后台上传响应:", res);
- if (res.code === 2e3) {
- const videoUrl = res.data.url || res.data.photoUrl || "";
- if (videoUrl) {
- this.uploadStatus[task.id] = "success";
- this.updateUploadStatusText();
- this.submitVideoToInterviewBackground(videoUrl, task);
- } else {
- this.handleBackgroundUploadFailure(task, "视频URL获取失败");
- }
- } else {
- this.handleBackgroundUploadFailure(task, res.msg || "上传失败");
- }
- } catch (e) {
- this.handleBackgroundUploadFailure(task, "解析响应失败");
- }
- } else {
- this.handleBackgroundUploadFailure(task, "HTTP状态: " + xhr.status);
- }
- };
- xhr.onerror = () => {
- this.handleBackgroundUploadFailure(task, "网络错误");
- };
- xhr.ontimeout = () => {
- this.handleBackgroundUploadFailure(task, "上传超时");
- };
- xhr.open("POST", `${common_config.apiBaseUrl}/api/upload/`);
- xhr.send(formData);
- },
- // 添加新方法:使用uni.uploadFile后台上传文件
- uploadFileWithUniBackground(task) {
- const userInfo = common_vendor.index.getStorageSync("userInfo");
- const openid = userInfo ? JSON.parse(userInfo).openid || "" : "";
- const tenant_id = common_vendor.index.getStorageSync("tenant_id") || JSON.parse(common_vendor.index.getStorageSync("userInfo")).tenant_id || "1";
- const uploadTask = common_vendor.index.uploadFile({
- url: `${common_config.apiBaseUrl}/api/upload/`,
- filePath: task.file,
- name: "file",
- formData: {
- openid,
- tenant_id,
- application_id: common_vendor.index.getStorageSync("appId"),
- question_id: task.questionId,
- video_duration: task.videoDuration || 0,
- has_audio: "true"
- },
- success: (uploadRes) => {
- try {
- const res = JSON.parse(uploadRes.data);
- console.log("后台上传响应:", res);
- if (res.code === 2e3) {
- const videoUrl = res.data.permanent_link || res.data.url || "";
- if (videoUrl) {
- this.uploadStatus[task.id] = "success";
- this.updateUploadStatusText();
- this.submitVideoToInterviewBackground(videoUrl, task);
- } else {
- this.handleBackgroundUploadFailure(task, "视频URL获取失败");
- }
- } else {
- this.handleBackgroundUploadFailure(task, res.msg || "上传失败");
- }
- } catch (e) {
- this.handleBackgroundUploadFailure(task, "解析响应失败");
- }
- },
- fail: (err) => {
- this.handleBackgroundUploadFailure(task, err.errMsg || "上传失败");
- }
- });
- uploadTask.onProgressUpdate((res) => {
- this.uploadProgress[task.id] = res.progress;
- this.updateUploadStatusText();
- });
- },
- // 添加新方法:处理后台上传失败
- handleBackgroundUploadFailure(task, errorMsg) {
- console.error("后台上传失败:", errorMsg);
- this.uploadStatus[task.id] = "failed";
- this.updateUploadStatusText();
- if (task.attempts < task.maxAttempts) {
- console.log(`将在5秒后重试后台上传,当前尝试次数: ${task.attempts}/${task.maxAttempts}`);
- setTimeout(() => {
- this.uploadProgress[task.id] = 0;
- if (typeof task.file !== "string") {
- this.uploadFileWithXHRBackground(task);
- } else {
- this.uploadFileWithUniBackground(task);
- }
- }, 5e3);
- } else {
- console.log("超过最大重试次数,放弃后台上传");
- if (this.backgroundUploadQueue) {
- const taskIndex = this.backgroundUploadQueue.findIndex((t) => t.id === task.id);
- if (taskIndex !== -1) {
- this.backgroundUploadQueue.splice(taskIndex, 1);
- }
- }
- this.processBackgroundUploadQueue();
- }
- },
- // 添加新方法:后台上传提交到面试接口
- submitVideoToInterviewBackground(videoUrl, task) {
- const followUpRequestData = {
- application_id: common_vendor.index.getStorageSync("appId"),
- tenant_id: common_vendor.index.getStorageSync("tenant_id") || JSON.parse(common_vendor.index.getStorageSync("userInfo")).tenant_id || "1",
- video_url: videoUrl,
- original_question_id: this.parentJobPositionQuestionId,
- // 使用保存的job_position_question_id
- follow_up_question: task.questionText,
- video_duration: task.videoDuration,
- openid: JSON.parse(common_vendor.index.getStorageSync("userInfo")).openid || ""
- };
- console.log("后台上传提交追问视频:", followUpRequestData);
- common_vendor.index.request({
- url: `${common_config.apiBaseUrl}/voice_interview/upload_follow_up_video/`,
- method: "POST",
- data: followUpRequestData,
- header: {
- "content-type": "application/x-www-form-urlencoded"
- },
- success: (res) => {
- if (res.data.code === 200 || res.data.code === 2e3) {
- console.log("后台上传追问视频提交成功");
- if (this.backgroundUploadQueue) {
- const taskIndex = this.backgroundUploadQueue.findIndex((t) => t.id === task.id);
- if (taskIndex !== -1) {
- this.backgroundUploadQueue.splice(taskIndex, 1);
- }
- }
- this.processBackgroundUploadQueue();
- } else {
- this.handleBackgroundSubmitFailure(task, "提交失败: " + (res.data.msg || "未知错误"));
- }
- },
- fail: (err) => {
- console.error("后台上传提交失败:", err);
- this.handleBackgroundSubmitFailure(task, "提交失败: " + err.errMsg);
- }
- });
- },
- // 添加新方法:处理后台上传提交失败
- handleBackgroundSubmitFailure(task, errorMsg) {
- console.error("后台上传提交失败:", errorMsg);
- if (task.attempts < task.maxAttempts) {
- console.log(`将在5秒后重试后台上传提交,当前尝试次数: ${task.attempts}/${task.maxAttempts}`);
- setTimeout(() => {
- this.submitVideoToInterviewBackground(task.videoUrl, task);
- }, 5e3);
- } else {
- console.log("超过最大重试次数,放弃后台上传提交");
- if (this.backgroundUploadQueue) {
- const taskIndex = this.backgroundUploadQueue.findIndex((t) => t.id === task.id);
- if (taskIndex !== -1) {
- this.backgroundUploadQueue.splice(taskIndex, 1);
- }
- }
- this.processBackgroundUploadQueue();
- }
- },
- // 添加新方法:处理上传后的逻辑
- handlePostUploadActions(task) {
- this.hideThinkingLoading();
- if (this.needPlayLowScoreVideo && this.retryCount < 1) {
- this.playLowScoreVideo();
- this.needPlayLowScoreVideo = false;
- } else {
- if (task.isFollowUp) {
- console.log("追问问题回答完成,检查是否继续追问");
- this.retryCount = 0;
- this.isFollowUpQuestion = false;
- this.currentFollowUpQuestion = null;
- this.videoUrl = "";
- this.maybeRequestNextFollowUp(this.parentJobPositionQuestionId);
- } else {
- console.log("常规问题回答完成,准备检查追问,父问题ID:", this.parentJobPositionQuestionId);
- if (this.parentJobPositionQuestionId) {
- const currentQuestion = this.getCurrentQuestionByIndex(this.currentVideoIndex);
- if (currentQuestion && typeof currentQuestion.follow_up_count !== "undefined") {
- this.setFollowUpLimit(this.parentJobPositionQuestionId, currentQuestion.follow_up_count);
- } else if (typeof this.defaultFollowUpLimit !== "undefined") {
- this.setFollowUpLimit(this.parentJobPositionQuestionId, this.defaultFollowUpLimit);
- }
- this.resetFollowUpAskedCount(this.parentJobPositionQuestionId);
- this.checkAndPlayFollowUpQuestion(this.parentJobPositionQuestionId);
- } else {
- console.error("缺少parentJobPositionQuestionId,无法检查追问,直接进入下一题");
- this.proceedToNextQuestion();
- }
- }
- }
- },
- // 修改 processUploadQueue 方法
- processUploadQueue() {
- if (this.uploadQueue.length === 0) {
- this.isUploading = false;
- this.showUploadStatus = false;
- this.hideThinkingLoading();
- return;
- }
- this.isUploading = true;
- this.showUploadStatus = true;
- const task = this.uploadQueue[0];
- this.uploadStatus[task.id] = "uploading";
- this.updateUploadStatusText();
- task.attempts++;
- if (typeof task.file === "string") {
- this.uploadFileWithUni(task);
- } else {
- this.uploadFileWithXHR(task);
- }
- },
- // 添加新方法:使用XMLHttpRequest上传文件
- uploadFileWithXHR(task) {
- const userInfo = common_vendor.index.getStorageSync("userInfo");
- const openid = userInfo ? JSON.parse(userInfo).openid || "" : "";
- const tenant_id = common_vendor.index.getStorageSync("tenant_id") || JSON.parse(common_vendor.index.getStorageSync("userInfo")).tenant_id || "1";
- const formData = new FormData();
- formData.append("file", task.file);
- formData.append("openid", openid);
- formData.append("tenant_id", tenant_id);
- formData.append("application_id", common_vendor.index.getStorageSync("appId"));
- formData.append("question_id", task.questionId);
- formData.append("video_duration", task.videoDuration);
- formData.append("has_audio", "true");
- const xhr = new XMLHttpRequest();
- xhr.open("POST", `${common_config.apiBaseUrl}/api/upload/`, true);
- xhr.timeout = 12e4;
- xhr.upload.onprogress = (event) => {
- if (event.lengthComputable) {
- const percentComplete = Math.round(event.loaded / event.total * 100);
- this.uploadProgress[task.id] = percentComplete;
- this.updateUploadStatusText();
- }
- };
- xhr.onload = () => {
- if (xhr.status === 200) {
- try {
- const res = JSON.parse(xhr.responseText);
- console.log("上传响应:", res);
- if (res.code === 2e3) {
- const videoUrl = res.data.url || res.data.photoUrl || "";
- if (videoUrl) {
- this.uploadStatus[task.id] = "success";
- this.updateUploadStatusText();
- this.submitVideoToInterview(videoUrl, task);
- } else {
- this.handleUploadFailure(task, "视频URL获取失败");
- }
- } else {
- this.handleUploadFailure(task, res.msg || "上传失败");
- }
- } catch (e) {
- this.handleUploadFailure(task, "解析响应失败");
- }
- } else {
- this.handleUploadFailure(task, "HTTP状态: " + xhr.status);
- }
- };
- xhr.onerror = () => {
- this.handleUploadFailure(task, "网络错误");
- };
- xhr.ontimeout = () => {
- this.handleUploadFailure(task, "上传超时");
- };
- xhr.send(formData);
- },
- // 添加新方法:使用uni.uploadFile上传文件
- uploadFileWithUni(task) {
- const userInfo = common_vendor.index.getStorageSync("userInfo");
- const openid = userInfo ? JSON.parse(userInfo).openid || "" : "";
- const tenant_id = common_vendor.index.getStorageSync("tenant_id") || JSON.parse(common_vendor.index.getStorageSync("userInfo")).tenant_id || "1";
- const uploadTask = common_vendor.index.uploadFile({
- url: `${common_config.apiBaseUrl}/api/upload/`,
- filePath: task.file,
- name: "file",
- formData: {
- openid,
- tenant_id,
- application_id: common_vendor.index.getStorageSync("appId"),
- question_id: task.questionId,
- video_duration: 0,
- has_audio: "true"
- },
- success: (uploadRes) => {
- try {
- const res = JSON.parse(uploadRes.data);
- console.log("上传响应:", res);
- if (res.code === 2e3) {
- const videoUrl = res.data.permanent_link || res.data.url || "";
- if (videoUrl) {
- this.uploadStatus[task.id] = "success";
- this.updateUploadStatusText();
- this.submitVideoToInterview(videoUrl, task);
- } else {
- this.handleUploadFailure(task, "视频URL获取失败");
- }
- } else {
- this.handleUploadFailure(task, res.msg || "上传失败");
- }
- } catch (e) {
- this.handleUploadFailure(task, "解析响应失败");
- }
- },
- fail: (err) => {
- this.handleUploadFailure(task, err.errMsg || "上传失败");
- }
- });
- uploadTask.onProgressUpdate((res) => {
- this.uploadProgress[task.id] = res.progress;
- this.updateUploadStatusText();
- });
- },
- // 添加新方法:处理上传失败
- handleUploadFailure(task, errorMsg) {
- console.error("上传失败:", errorMsg);
- this.uploadStatus[task.id] = "failed";
- this.updateUploadStatusText();
- if (task.attempts < task.maxAttempts) {
- console.log(`将在5秒后重试上传,当前尝试次数: ${task.attempts}/${task.maxAttempts}`);
- setTimeout(() => {
- this.uploadProgress[task.id] = 0;
- if (typeof task.file !== "string") {
- this.uploadFileWithXHR(task);
- } else {
- this.uploadFileWithUni(task);
- }
- }, 5e3);
- } else {
- console.log("超过最大重试次数,放弃上传");
- this.uploadQueue.shift();
- this.processUploadQueue();
- }
- },
- // 修改 submitVideoToInterview 方法
- submitVideoToInterview(videoUrl, task) {
- const requestData = {
- application_id: common_vendor.index.getStorageSync("appId"),
- question_id: task.questionId,
- video_url: videoUrl,
- tenant_id: common_vendor.index.getStorageSync("tenant_id") || JSON.parse(common_vendor.index.getStorageSync("userInfo")).tenant_id || "1",
- is_follow_up: task.isFollowUp ? 1 : 0,
- question_form: task.questionForm,
- question_text: task.questionText
- };
- console.log("提交视频到面试接口", requestData);
- if (task.isFollowUp) {
- const followUpRequestData = {
- application_id: common_vendor.index.getStorageSync("appId"),
- tenant_id: common_vendor.index.getStorageSync("tenant_id") || JSON.parse(common_vendor.index.getStorageSync("userInfo")).tenant_id || "1",
- video_url: videoUrl,
- original_question_id: this.parentJobPositionQuestionId,
- // 使用保存的job_position_question_id
- follow_up_question: task.questionText,
- video_duration: task.videoDuration,
- openid: JSON.parse(common_vendor.index.getStorageSync("userInfo")).openid || ""
- };
- console.log("准备提交追问视频:", followUpRequestData);
- common_vendor.index.request({
- url: `${common_config.apiBaseUrl}/voice_interview/upload_follow_up_video/`,
- method: "POST",
- data: followUpRequestData,
- header: {
- "content-type": "application/x-www-form-urlencoded"
- },
- success: async (res) => {
- try {
- if (res.data.code === 200 || res.data.code === 2e3) {
- if (res.data.data && res.data.data.transcription_status === "pending") {
- console.log("视频转写进行中,5秒后重试");
- setTimeout(() => {
- this.checkTranscriptionStatus(task, followUpRequestData);
- }, 5e3);
- return;
- }
- console.log("追问视频提交成功");
- this.isFollowUpMode = false;
- this.currentVideoIndex = this.mainQuestionIndex;
- this.uploadQueue.shift();
- this.processUploadQueue();
- this.$nextTick(() => {
- if (this.currentVideoIndex < this.videoList.length) {
- this.videoUrl = this.videoList[this.currentVideoIndex];
- this.videoPlaying = true;
- const videoContext = common_vendor.index.createVideoContext("myVideo", this);
- if (videoContext) {
- videoContext.play();
- }
- }
- });
- } else {
- this.handleSubmitFailure(task, "提交失败: " + (res.data.msg || "未知错误"));
- }
- } catch (e) {
- this.handleSubmitFailure(task, "解析响应失败: " + e.message);
- }
- },
- fail: (err) => {
- console.error("提交视频失败:", err);
- this.handleSubmitFailure(task, "提交失败: " + err.errMsg);
- }
- });
- } else {
- common_vendor.index.request({
- url: `${common_config.apiBaseUrl}/api/job/upload_video`,
- method: "POST",
- data: requestData,
- header: {
- "content-type": "application/x-www-form-urlencoded"
- },
- success: async (res) => {
- if (res.data.code === 200 || res.data.code === 2e3) {
- console.log("视频提交成功,准备调用面试互动接口");
- try {
- this.parentJobPositionQuestionId = res.data.data.job_position_question_id;
- console.log("保存父问题ID:", this.parentJobPositionQuestionId);
- const limitFromServer = res.data.data.follow_up_limit;
- if (typeof limitFromServer !== "undefined") {
- this.setFollowUpLimit(this.parentJobPositionQuestionId, limitFromServer);
- } else {
- this.setFollowUpLimit(this.parentJobPositionQuestionId, this.defaultFollowUpLimit);
- }
- this.resetFollowUpAskedCount(this.parentJobPositionQuestionId);
- await this.callInterviewInteraction(res.data.data.job_position_question_id);
- console.log("面试互动接口调用成功");
- } catch (error) {
- console.error("面试互动接口调用失败:", error);
- this.proceedToNextQuestion();
- }
- this.uploadQueue.shift();
- this.processUploadQueue();
- } else {
- this.handleSubmitFailure(task, "提交失败: " + (res.data.msg || "未知错误"));
- }
- },
- fail: (err) => {
- console.error("提交视频失败:", err);
- this.handleSubmitFailure(task, "提交失败: " + err.errMsg);
- }
- });
- }
- },
- // 添加新方法:处理提交失败
- handleSubmitFailure(task, errorMsg) {
- console.error("提交失败:", errorMsg);
- this.uploadStatus[task.id] = "failed";
- this.updateUploadStatusText();
- if (task.attempts < task.maxAttempts) {
- console.log(`将在5秒后重试提交,当前尝试次数: ${task.attempts}/${task.maxAttempts}`);
- setTimeout(() => {
- this.submitVideoToInterview(task.videoUrl, task);
- }, 5e3);
- } else {
- console.log("超过最大重试次数,放弃提交");
- this.uploadQueue.shift();
- this.processUploadQueue();
- }
- },
- // 添加检查转写状态的方法
- checkTranscriptionStatus(task, requestData, retryCount = 0) {
- const maxRetries = 24;
- const retryInterval = 5e3;
- if (retryCount >= maxRetries) {
- console.log("转写超时,继续下一个问题");
- this.isFollowUpMode = false;
- this.currentVideoIndex = this.mainQuestionIndex;
- this.uploadQueue.shift();
- this.processUploadQueue();
- return;
- }
- common_vendor.index.request({
- url: `${common_config.apiBaseUrl}/voice_interview/check_transcription_status/`,
- method: "POST",
- data: {
- application_id: requestData.application_id,
- original_question_id: requestData.original_question_id,
- video_url: requestData.video_url
- },
- header: {
- "content-type": "application/x-www-form-urlencoded"
- },
- success: (res) => {
- if (res.data.code === 200 || res.data.code === 2e3) {
- if (res.data.data && res.data.data.status === "completed") {
- console.log("视频转写完成");
- this.isFollowUpMode = false;
- this.currentVideoIndex = this.mainQuestionIndex;
- this.uploadQueue.shift();
- this.processUploadQueue();
- this.$nextTick(() => {
- if (this.currentVideoIndex < this.videoList.length) {
- this.videoUrl = this.videoList[this.currentVideoIndex];
- this.videoPlaying = true;
- const videoContext = common_vendor.index.createVideoContext("myVideo", this);
- if (videoContext) {
- videoContext.play();
- }
- }
- });
- } else {
- console.log(`转写进行中,${retryInterval / 1e3}秒后重试 (${retryCount + 1}/${maxRetries})`);
- setTimeout(() => {
- this.checkTranscriptionStatus(task, requestData, retryCount + 1);
- }, retryInterval);
- }
- } else if (res.data.message === "面试视频尚未完成转写" || res.data.success === false) {
- console.log(`转写未完成,${retryInterval / 1e3}秒后重试 (${retryCount + 1}/${maxRetries})`);
- setTimeout(() => {
- this.checkTranscriptionStatus(task, requestData, retryCount + 1);
- }, retryInterval);
- } else {
- this.handleSubmitFailure(task, "检查转写状态失败: " + (res.data.msg || "未知错误"));
- }
- },
- fail: (err) => {
- console.error("检查转写状态失败:", err);
- console.log(`网络请求失败,${retryInterval / 1e3}秒后重试 (${retryCount + 1}/${maxRetries})`);
- setTimeout(() => {
- this.checkTranscriptionStatus(task, requestData, retryCount + 1);
- }, retryInterval);
- }
- });
- },
- // 添加新方法:更新上传状态文本
- updateUploadStatusText() {
- let mainQueueText = "";
- if (this.uploadQueue.length > 0) {
- const currentTask = this.uploadQueue[0];
- const progress = this.uploadProgress[currentTask.id] || 0;
- const status = this.uploadStatus[currentTask.id] || "pending";
- let statusText = "";
- switch (status) {
- case "pending":
- statusText = "等待上传";
- break;
- case "uploading":
- statusText = `上传中 ${progress}%`;
- break;
- case "success":
- statusText = "上传成功,提交中...";
- break;
- case "failed":
- statusText = `上传失败,${currentTask.attempts < currentTask.maxAttempts ? "即将重试" : "已放弃"}`;
- break;
- }
- const questionTypeText = currentTask.isFollowUp ? "追问" : "问题";
- const questionShortText = currentTask.questionText ? currentTask.questionText.length > 10 ? currentTask.questionText.substring(0, 10) + "..." : currentTask.questionText : `${questionTypeText}${currentTask.questionId}`;
- mainQueueText = `${questionTypeText}「${questionShortText}」:${statusText}`;
- if (this.uploadQueue.length > 1) {
- mainQueueText += ` (${this.uploadQueue.length}个视频待处理)`;
- }
- }
- let backgroundQueueText = "";
- if (this.backgroundUploadQueue && this.backgroundUploadQueue.length > 0) {
- const currentTask = this.backgroundUploadQueue[0];
- const progress = this.uploadProgress[currentTask.id] || 0;
- const status = this.uploadStatus[currentTask.id] || "pending";
- let statusText = "";
- switch (status) {
- case "pending":
- statusText = "等待后台上传";
- break;
- case "uploading":
- statusText = `后台上传中 ${progress}%`;
- break;
- case "success":
- statusText = "后台上传成功,提交中...";
- break;
- case "failed":
- statusText = `后台上传失败,${currentTask.attempts < currentTask.maxAttempts ? "即将重试" : "已放弃"}`;
- break;
- }
- const questionShortText = currentTask.questionText ? currentTask.questionText.length > 10 ? currentTask.questionText.substring(0, 10) + "..." : currentTask.questionText : `追问${currentTask.questionId}`;
- backgroundQueueText = `追问「${questionShortText}」:${statusText}`;
- if (this.backgroundUploadQueue.length > 1) {
- backgroundQueueText += ` (${this.backgroundUploadQueue.length}个追问待后台上传)`;
- }
- }
- if (mainQueueText && backgroundQueueText) {
- this.uploadStatusText = `${mainQueueText} | ${backgroundQueueText}`;
- } else if (mainQueueText) {
- this.uploadStatusText = mainQueueText;
- } else if (backgroundQueueText) {
- this.uploadStatusText = backgroundQueueText;
- } else {
- this.uploadStatusText = "";
- }
- },
- // 修改 proceedToNextQuestion 方法,确保在切换视频时重置历史时间
- proceedToNextQuestion() {
- if (this.isVideoSwitching) {
- console.log("正在切换视频中,请等待...");
- return;
- }
- console.log("继续下一个问题");
- this.isVideoSwitching = true;
- const currentVideo = common_vendor.index.createVideoContext("myVideo", this);
- if (currentVideo) {
- currentVideo.stop();
- this.videoPlaying = false;
- }
- if (this.currentVideoIndex + 1 >= this.videoList.length) {
- this.stopUserCamera();
- this.clearCountdown();
- const currentJobDetail = JSON.parse(common_vendor.index.getStorageSync("selectedJob"));
- const jobId = currentJobDetail ? currentJobDetail.id : null;
- this.handleVideoCompletion(jobId);
- return;
- }
- this.currentVideoIndex++;
- this.historyTime = 0;
- if (this.currentVideoIndex < this.videoList.length) {
- this.videoUrl = this.videoList[this.currentVideoIndex];
- this.$nextTick(() => {
- this.videoPlaying = true;
- const videoContext = common_vendor.index.createVideoContext("myVideo", this);
- if (videoContext) {
- videoContext.play();
- }
- this.isVideoSwitching = false;
- });
- } else {
- console.log("所有视频已播放完毕");
- this.stopUserCamera();
- this.clearCountdown();
- const currentJobDetail = JSON.parse(common_vendor.index.getStorageSync("selectedJob"));
- console.log("当前职位ID:", currentJobDetail);
- const jobId = currentJobDetail ? currentJobDetail.id : null;
- console.log("当前职位ID:", jobId);
- setTimeout(() => {
- this.isVideoSwitching = false;
- if (jobId === 9) {
- common_vendor.index.navigateTo({
- url: "/pages/interview-question/interview-question",
- success: () => {
- console.log("成功跳转到interview-question页面");
- },
- fail: (err) => {
- console.error("跳转到interview-question页面失败:", err);
- common_vendor.index.redirectTo({
- url: "/pages/interview-question/interview-question",
- fail: (redirectErr) => {
- console.error("重定向到interview-question页面也失败:", redirectErr);
- common_vendor.index.navigateBack({
- delta: 1
- });
- }
- });
- }
- });
- } else {
- common_vendor.index.navigateTo({
- url: "/pages/camera/camera",
- success: () => {
- console.log("成功跳转到camera页面");
- },
- fail: (err) => {
- console.error("跳转到camera页面失败:", err);
- common_vendor.index.redirectTo({
- url: "/pages/camera/camera",
- fail: (redirectErr) => {
- console.error("重定向到camera页面也失败:", redirectErr);
- common_vendor.index.switchTab({
- url: "/pages/camera/camera",
- fail: (switchErr) => {
- console.error("所有跳转方式都失败:", switchErr);
- common_vendor.index.navigateBack({
- delta: 1
- });
- }
- });
- }
- });
- }
- });
- }
- }, 0);
- }
- },
- // 修改 handleAnswerButtonClick 方法,确保在切换视频时重置历史时间
- handleAnswerButtonClick() {
- console.log("点击开始回答按钮");
- this.showAnswerButton = false;
- this.currentVideoIndex++;
- this.historyTime = 0;
- if (this.currentVideoIndex < this.videoList.length) {
- this.videoUrl = this.videoList[this.currentVideoIndex];
- this.videoPlaying = true;
- this.$nextTick(() => {
- const videoContext = common_vendor.index.createVideoContext("myVideo", this);
- if (videoContext) {
- videoContext.play();
- }
- });
- }
- },
- // 处理相机错误
- handleCameraError(e) {
- console.error("相机错误:", e);
- const systemInfo = common_vendor.index.getSystemInfoSync();
- const isIOS = systemInfo.platform === "ios";
- if (isIOS) {
- console.log("iOS相机错误,尝试重新初始化");
- common_vendor.index.showToast({
- title: "相机初始化中...",
- icon: "loading",
- duration: 2e3
- });
- this.resetCamera();
- if (this.isRecording) {
- this.isRecording = false;
- this.showStopRecordingButton = false;
- setTimeout(() => {
- this.useAlternativeRecordingMethod();
- }, 1e3);
- }
- } else {
- common_vendor.index.showToast({
- title: "相机初始化失败,请检查权限设置",
- icon: "none"
- });
- this.tryFallbackOptions();
- }
- },
- // 添加新方法:尝试备用选项
- tryFallbackOptions() {
- const systemInfo = common_vendor.index.getSystemInfoSync();
- if (systemInfo.uniPlatform === "mp-weixin" || systemInfo.uniPlatform === "mp-alipay") {
- this.useMiniProgramCamera();
- } else {
- this.showStaticCameraPlaceholder();
- }
- },
- // 添加新方法:使用小程序相机API
- useMiniProgramCamera() {
- console.log("尝试使用小程序相机组件");
- this.useMiniProgramCameraComponent = true;
- },
- // 添加新方法:显示静态图像
- showStaticCameraPlaceholder() {
- console.log("显示静态摄像头占位图");
- const img = document.createElement("img");
- img.src = "/static/images/camera-placeholder.png";
- img.className = "static-camera-image";
- img.style.width = "100%";
- img.style.height = "100%";
- img.style.objectFit = "cover";
- const container = this.$refs.userCameraVideo.parentNode;
- container.appendChild(img);
- },
- // 修改 handleTimeUpdate 方法
- handleTimeUpdate(e) {
- const currentTime = e.detail.currentTime || e.target.currentTime;
- if (this.isRecording && this.recordingTimerCount) {
- this.recordingTimeDisplay = this.formatTime(this.recordingTimerCount);
- }
- if (this.isPlayingLowScoreVideo) {
- if (this.lowScoreVideoSubtitles && this.lowScoreVideoSubtitles.length > 0) {
- const subtitle = this.lowScoreVideoSubtitles[0];
- this.currentSubtitle = subtitle.text;
- }
- return;
- }
- let currentSubtitles = null;
- if (this.isFollowUpQuestion && this.currentFollowUpQuestion) {
- const subtitleKey = `followUpSubtitles_${this.currentFollowUpQuestion.id}`;
- currentSubtitles = this[subtitleKey] || [{
- startTime: 0,
- endTime: 30,
- text: this.currentFollowUpQuestion.question || this.currentFollowUpQuestion.question
- }];
- } else {
- if (this.currentVideoIndex === 0) {
- currentSubtitles = this.subtitles;
- } else {
- const subtitleArrayName = `question${this.currentVideoIndex}Subtitles`;
- currentSubtitles = this[subtitleArrayName];
- }
- }
- if (currentSubtitles && currentSubtitles.length > 0) {
- const subtitle = currentSubtitles.find(
- (sub) => currentTime >= sub.startTime && currentTime <= sub.endTime
- ) || currentSubtitles[0];
- if (subtitle) {
- this.currentSubtitle = subtitle.text;
- }
- }
- this.historyTime = currentTime;
- this.lastUpdateTime = Date.now();
- },
- // Add a new method to handle the "Start Recording" button click
- handleStartRecordingClick() {
- this.showStartRecordingButton = false;
- this.clearCountdown();
- this.isWaitingForAnswer = false;
- this.startRecordingAnswer();
- },
- // 修改 checkAudioPermission 方法,确保在录制前获取音频权限
- checkAudioPermission() {
- const systemInfo = common_vendor.index.getSystemInfoSync();
- const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith("mp-");
- if (isMiniProgram) {
- common_vendor.index.getSetting({
- success: (res) => {
- if (!res.authSetting["scope.record"]) {
- common_vendor.index.authorize({
- scope: "scope.record",
- success: () => {
- console.log("录音权限已获取");
- },
- fail: (err) => {
- console.error("录音权限获取失败:", err);
- this.showPermissionDialog("录音");
- }
- });
- }
- if (!res.authSetting["scope.camera"]) {
- common_vendor.index.authorize({
- scope: "scope.camera",
- success: () => {
- console.log("相机权限已获取");
- },
- fail: (err) => {
- console.error("相机权限获取失败:", err);
- this.showPermissionDialog("相机");
- }
- });
- }
- }
- });
- }
- },
- // 添加新方法:测试音频输入
- testAudioInput() {
- if (!this.cameraStream) {
- console.warn("没有可用的媒体流,无法测试音频");
- return;
- }
- const audioTracks = this.cameraStream.getAudioTracks();
- if (audioTracks.length === 0) {
- console.warn("没有检测到音频轨道,尝试重新获取");
- this.tryGetAudioOnly();
- return;
- }
- console.log("音频轨道信息:", audioTracks[0].getSettings());
- try {
- const AudioContext = window.AudioContext || window.webkitAudioContext;
- if (!AudioContext) {
- console.warn("浏览器不支持AudioContext");
- return;
- }
- const audioContext = new AudioContext();
- const analyser = audioContext.createAnalyser();
- const microphone = audioContext.createMediaStreamSource(this.cameraStream);
- microphone.connect(analyser);
- analyser.fftSize = 256;
- const bufferLength = analyser.frequencyBinCount;
- const dataArray = new Uint8Array(bufferLength);
- let silenceCounter = 0;
- const checkAudio = () => {
- if (this.isRecording)
- return;
- analyser.getByteFrequencyData(dataArray);
- let sum = 0;
- for (let i = 0; i < bufferLength; i++) {
- sum += dataArray[i];
- }
- const average = sum / bufferLength;
- if (average > 10) {
- console.log("检测到音频输入,音量:", average);
- silenceCounter = 0;
- } else {
- silenceCounter++;
- if (silenceCounter > 10) {
- console.warn("持续检测不到音频输入,可能麦克风未正常工作");
- silenceCounter = 0;
- }
- }
- requestAnimationFrame(checkAudio);
- };
- checkAudio();
- } catch (e) {
- console.error("音频测试失败:", e);
- }
- },
- // 添加新方法:尝试单独获取音频
- tryGetAudioOnly() {
- navigator.mediaDevices.getUserMedia({ audio: true }).then((audioStream) => {
- if (this.cameraStream) {
- const videoTrack = this.cameraStream.getVideoTracks()[0];
- const audioTrack = audioStream.getAudioTracks()[0];
- const combinedStream = new MediaStream();
- if (videoTrack)
- combinedStream.addTrack(videoTrack);
- if (audioTrack)
- combinedStream.addTrack(audioTrack);
- this.cameraStream = combinedStream;
- const videoElement = this.$refs.userCameraVideo;
- if (videoElement) {
- videoElement.srcObject = combinedStream;
- videoElement.muted = true;
- }
- console.log("成功合并音频和视频轨道");
- } else {
- console.warn("没有视频流可合并");
- }
- }).catch((err) => {
- console.error("单独获取音频失败:", err);
- });
- },
- // 添加新方法:显示权限对话框
- showPermissionDialog(permissionType) {
- common_vendor.index.showModal({
- title: "需要权限",
- content: `请允许使用${permissionType}权限,否则可能影响面试功能`,
- confirmText: "去设置",
- success: (res) => {
- if (res.confirm) {
- common_vendor.index.openSetting({
- success: (settingRes) => {
- console.log("设置页面打开成功", settingRes);
- }
- });
- }
- }
- });
- },
- // 添加重试上传方法
- retryVideoUpload() {
- if (this.lastVideoToRetry) {
- this.showRetryButton = false;
- common_vendor.index.showLoading({
- title: "正在重新提交...",
- mask: true
- });
- this.submitVideoToInterview(this.lastVideoToRetry);
- } else {
- common_vendor.index.showToast({
- title: "没有可重试的视频",
- icon: "none"
- });
- }
- },
- // 添加一个新方法用于压缩视频
- async compressVideo(videoBlob) {
- if (videoBlob.size < 5 * 1024 * 1024) {
- return videoBlob;
- }
- console.log("开始压缩视频,原始大小:", videoBlob.size);
- const videoElement = document.createElement("video");
- videoElement.muted = true;
- videoElement.autoplay = false;
- const canvas = document.createElement("canvas");
- const ctx = canvas.getContext("2d");
- videoElement.src = URL.createObjectURL(videoBlob);
- return new Promise((resolve) => {
- videoElement.onloadedmetadata = () => {
- const width = Math.floor(videoElement.videoWidth / 2);
- const height = Math.floor(videoElement.videoHeight / 2);
- canvas.width = width;
- canvas.height = height;
- const stream = canvas.captureStream(15);
- if (videoElement.captureStream) {
- const originalStream = videoElement.captureStream();
- const audioTracks = originalStream.getAudioTracks();
- if (audioTracks.length > 0) {
- stream.addTrack(audioTracks[0]);
- }
- }
- const options = {
- mimeType: "video/webm;codecs=vp8,opus",
- audioBitsPerSecond: 64e3,
- videoBitsPerSecond: 8e5
- // 800kbps
- };
- const mediaRecorder = new MediaRecorder(stream, options);
- const chunks = [];
- mediaRecorder.ondataavailable = (e) => {
- if (e.data.size > 0) {
- chunks.push(e.data);
- }
- };
- mediaRecorder.onstop = () => {
- const compressedBlob = new Blob(chunks, { type: "video/webm" });
- console.log("视频压缩完成,压缩后大小:", compressedBlob.size);
- resolve(compressedBlob);
- };
- videoElement.onplay = () => {
- mediaRecorder.start(10);
- const drawFrame = () => {
- if (videoElement.paused || videoElement.ended) {
- mediaRecorder.stop();
- return;
- }
- ctx.drawImage(videoElement, 0, 0, width, height);
- requestAnimationFrame(drawFrame);
- };
- drawFrame();
- };
- videoElement.play();
- };
- });
- },
- // 修改 checkIOSCameraRecordPermission 方法
- checkIOSCameraRecordPermission() {
- const systemInfo = common_vendor.index.getSystemInfoSync();
- if (systemInfo.platform !== "ios")
- return;
- common_vendor.index.getSetting({
- success: (res) => {
- if (!res.authSetting["scope.camera"]) {
- common_vendor.index.authorize({
- scope: "scope.camera",
- success: () => {
- console.log("iOS相机权限已获取");
- },
- fail: (err) => {
- console.error("iOS相机权限获取失败:", err);
- this.showPermissionDialog("相机");
- }
- });
- }
- if (!res.authSetting["scope.record"]) {
- common_vendor.index.authorize({
- scope: "scope.record",
- success: () => {
- console.log("iOS录音权限已获取");
- },
- fail: (err) => {
- console.error("iOS录音权限获取失败:", err);
- this.showPermissionDialog("录音");
- }
- });
- }
- }
- });
- },
- // 添加新方法:检查并修复渲染问题
- checkAndFixRenderingIssues() {
- try {
- if (typeof u !== "undefined" && u) {
- if (!u.currentQuestion) {
- console.log("修复: 创建缺失的currentQuestion对象");
- u.currentQuestion = {};
- }
- if (u.currentQuestion && typeof u.currentQuestion.isImportant === "undefined") {
- console.log("修复: 设置缺失的isImportant属性");
- u.currentQuestion.isImportant = false;
- }
- }
- } catch (e) {
- console.log("防御性检查异常:", e);
- }
- },
- // 添加格式化时间的辅助方法
- formatTime(seconds) {
- if (!seconds && seconds !== 0)
- return "03:30";
- const minutes = Math.floor(seconds / 60);
- const remainingSeconds = seconds % 60;
- return `${minutes.toString().padStart(2, "0")}:${remainingSeconds.toString().padStart(2, "0")}`;
- },
- // 添加获取问题数据的方法
- fetchQuestions() {
- this.loading = true;
- const tenant_id = common_vendor.index.getStorageSync("tenant_id") || JSON.parse(common_vendor.index.getStorageSync("userInfo")).tenant_id || "1";
- let position_id = 1;
- try {
- const selectedJob = JSON.parse(common_vendor.index.getStorageSync("selectedJob") || "{}");
- if (selectedJob && selectedJob.id) {
- position_id = selectedJob.id;
- console.log("使用选择的职位ID获取问题:", position_id);
- } else {
- console.warn("未找到选择的职位信息,使用默认职位ID:", position_id);
- }
- } catch (e) {
- console.error("解析职位信息失败:", e);
- }
- const timestamp = Date.now();
- const requestUrl = `${common_config.apiBaseUrl}/api/wechat/open_questions/?position_id=${position_id}&tenant_id=${tenant_id}&question_form=0&_t=${timestamp}`;
- console.log("完整的请求URL:", requestUrl);
- common_vendor.index.request({
- url: requestUrl,
- method: "GET",
- success: (res) => {
- if (res.data && res.data.code === 2e3 && res.data.data && res.data.data.items) {
- console.log("获取问题数据成功:", res.data.data.items);
- this.questions = res.data.data.items;
- this.processQuestionData();
- this.playIntroVideo();
- } else {
- console.error("获取问题数据失败:", res.data);
- common_vendor.index.showToast({
- title: "获取问题数据失败",
- icon: "none"
- });
- }
- },
- fail: (err) => {
- console.error("请求问题数据失败:", err);
- common_vendor.index.showToast({
- title: "网络错误,请检查网络连接",
- icon: "none"
- });
- },
- complete: () => {
- this.loading = false;
- }
- });
- },
- // 处理问题数据,提取视频URL和字幕
- processQuestionData() {
- this.videoList = [];
- this.videoList.push(this.introVideoUrl);
- const configStr = common_vendor.index.getStorageSync("configData");
- let openingSpeech = [];
- if (configStr) {
- try {
- const configData = JSON.parse(configStr);
- if (configData && configData.digital_human_opening_speech) {
- if (Array.isArray(configData.digital_human_opening_speech)) {
- openingSpeech = configData.digital_human_opening_speech.map((item, index, arr) => {
- const startTime = index === 0 ? 0 : arr[index - 1].end_time || index * 5;
- const endTime = item.end_time || (index + 1) * 5;
- return {
- startTime,
- endTime,
- text: item.content
- };
- });
- } else if (typeof configData.digital_human_opening_speech === "string") {
- openingSpeech = this.convertStringToSubtitles(configData.digital_human_opening_speech);
- }
- }
- } catch (error) {
- console.error("解析configData失败:", error);
- }
- }
- this.subtitles = openingSpeech.length > 0 ? openingSpeech : [
- {
- startTime: 0,
- endTime: 5,
- text: "你好,我是本次面试的面试官,欢迎参加本公司的线上面试!"
- },
- {
- startTime: 5,
- endTime: 13,
- text: "面试预计需要15分钟,请你提前安排在网络良好、光线亮度合适、且相对安静的环境参加这次面试"
- },
- {
- startTime: 13,
- endTime: 20,
- text: "以免影响本次面试的结果。如果你在面试过程中遇到问题,请与我们的招聘人员联系。"
- }
- ];
- console.log("处理后的字幕数据:", this.subtitles);
- const sortedQuestions = [...this.questions].sort((a, b) => a.sequence_number - b.sequence_number);
- const questionsToUse = sortedQuestions.slice(0, 5);
- questionsToUse.forEach((question, index) => {
- if (question.digital_human_video_url) {
- this.videoList.push(question.digital_human_video_url);
- const subtitleArray = [{
- startTime: 0,
- endTime: 30,
- // 延长字幕显示时间到30秒
- text: question.question || question.question
- }];
- const videoIndex = this.videoList.length - 1;
- this[`question${videoIndex}Subtitles`] = subtitleArray;
- this.subtitleMap[question.digital_human_video_url] = subtitleArray;
- }
- });
- if (this.videoList.length <= 1)
- ;
- else {
- console.log("处理后的视频列表:", this.videoList);
- console.log("处理后的字幕:", this.subtitles);
- }
- },
- // 将字符串类型的文本转换为字幕格式
- convertStringToSubtitles(text) {
- if (!text || typeof text !== "string") {
- return [];
- }
- const sentences = text.split(/([。!?!?])/).filter((part) => part.trim() !== "").reduce((acc, part, index, arr) => {
- if (index % 2 === 0) {
- const nextPart = arr[index + 1] || "";
- acc.push(part + nextPart);
- }
- return acc;
- }, []).filter((sentence) => sentence.trim().length > 0);
- if (sentences.length <= 1) {
- const maxLength = 30;
- const textParts = [];
- for (let i = 0; i < text.length; i += maxLength) {
- textParts.push(text.substring(i, i + maxLength));
- }
- sentences.splice(0, sentences.length, ...textParts);
- }
- let currentStartTime = 0;
- return sentences.map((sentence) => {
- const duration = Math.max(3, Math.ceil(sentence.length / 6));
- const startTime = currentStartTime;
- const endTime = startTime + duration;
- currentStartTime = endTime;
- return {
- startTime,
- endTime,
- text: sentence.trim()
- };
- });
- },
- // 使用默认视频和字幕(作为备用)
- useDefaultVideosAndSubtitles() {
- console.log("使用默认视频和字幕");
- this.subtitles = [
- {
- startTime: 0,
- endTime: 5,
- text: "你好,我是本次面试的面试官,欢迎参加本公司的线上面试!"
- },
- {
- startTime: 5,
- endTime: 13,
- text: "面试预计需要15分钟,请你提前安排在网络良好、光线亮度合适、且相对安静的环境参加这次面试"
- },
- {
- startTime: 13,
- endTime: 20,
- text: "以免影响本次面试的结果。如果你在面试过程中遇到问题,请与我们的招聘人员联系。"
- }
- ];
- this.question1Subtitles = [{
- startTime: 0,
- endTime: 10,
- text: "请结合您的基本信息与过往履历进行简单的自我介绍,并讲一讲您有哪些优势胜任本岗位:"
- }];
- this.question2Subtitles = [{
- startTime: 0,
- endTime: 4,
- text: "在工作中,你如何确保个人防护装备的正确使用?"
- }];
- this.question3Subtitles = [{
- startTime: 0,
- endTime: 4,
- text: "描述一次你与团队合作改善生产流程的经历。"
- }];
- this.question4Subtitles = [{
- startTime: 0,
- endTime: 6,
- text: "你在团队合作中曾遇到过哪些挑战?如何解决团队内部的分歧?"
- }];
- this.question5Subtitles = [{
- startTime: 0,
- endTime: 5,
- text: "您已完成本次面试全部题目,请问您对于这个岗位还有什么想要了解的吗?"
- }];
- },
- // 播放介绍视频
- playIntroVideo() {
- this.videoUrl = this.videoList[0];
- this.videoPlaying = true;
- this.$nextTick(() => {
- const videoContext = common_vendor.index.createVideoContext("myVideo", this);
- if (videoContext) {
- videoContext.play();
- }
- });
- },
- // 添加新方法:获取默认问题ID
- getDefaultQuestionId(videoIndex) {
- switch (videoIndex) {
- case 1:
- return 10;
- case 2:
- return 11;
- case 3:
- return 12;
- case 4:
- return 13;
- default:
- return 10;
- }
- },
- // 添加新方法:根据索引获取当前问题
- getCurrentQuestionByIndex(videoIndex) {
- const questionIndex = videoIndex - 1;
- const sortedQuestions = [...this.questions].sort((a, b) => a.sequence_number - b.sequence_number);
- if (questionIndex >= 0 && questionIndex < sortedQuestions.length) {
- return sortedQuestions[questionIndex];
- }
- return null;
- },
- // 添加新方法:获取当前问题的推荐录制时长
- getCurrentQuestionRecommendedDuration() {
- const currentQuestion = this.getCurrentQuestionByIndex(this.currentVideoIndex);
- if (currentQuestion && currentQuestion.recommended_duration) {
- const recommendedDuration = parseInt(currentQuestion.recommended_duration);
- console.log(`使用问题推荐时长: ${recommendedDuration}秒`);
- return recommendedDuration;
- }
- console.log("使用默认录制时长: 300秒");
- return 300;
- },
- // 添加新方法:重置录制状态,准备重新回答
- resetForRerecording() {
- console.log("重置录制状态,准备重新回答");
- this.isRecording = false;
- this.showStopRecordingButton = false;
- this.showStartRecordingButton = true;
- this.clearCountdown();
- if (this.recordingTimer) {
- clearInterval(this.recordingTimer);
- this.recordingTimer = null;
- }
- this.recordingTimerCount = 0;
- this.recordingTimeDisplay = "00:00 ";
- this.maxRecordingTime = this.getCurrentQuestionRecommendedDuration();
- this.remainingTime = this.maxRecordingTime;
- if (this.mediaRecorder && this.mediaRecorder.state !== "inactive") {
- this.mediaRecorder.stop();
- this.recordedChunks = [];
- }
- if (this.cameraContext) {
- this.cameraContext.stopRecord({
- success: () => {
- console.log("相机录制已停止");
- },
- fail: (err) => {
- console.error("停止相机录制失败:", err);
- }
- });
- }
- this.questionRetryMap = {};
- },
- // 修改 playLowScoreVideo 方法,优化字幕显示并添加重试次数限制
- playLowScoreVideo() {
- var _a;
- console.log("播放低分提示视频");
- const currentQuestionId = (_a = this.getCurrentQuestionByIndex(this.currentVideoIndex)) == null ? void 0 : _a.id;
- if (!currentQuestionId) {
- console.error("无法获取当前问题ID");
- return;
- }
- if (!this.questionRetryMap[currentQuestionId]) {
- this.questionRetryMap[currentQuestionId] = 1;
- } else {
- this.questionRetryMap[currentQuestionId]++;
- }
- if (this.questionRetryMap[currentQuestionId] > this.maxQuestionRetries) {
- console.log(`问题 ${currentQuestionId} 已超过最大重试次数,自动进入下一题`);
- this.isPlayingLowScoreVideo = false;
- this.isFollowUpQuestion = false;
- this.currentFollowUpQuestion = null;
- this.followUpQuestion = "";
- this.parentQuestion = "";
- this.currentVideoIndex++;
- if (this.currentVideoIndex < this.videoList.length) {
- const nextQuestion = this.getCurrentQuestionByIndex(this.currentVideoIndex);
- if (nextQuestion) {
- this.currentSubtitle = nextQuestion.question || nextQuestion.question;
- }
- this.videoUrl = this.videoList[this.currentVideoIndex];
- this.videoPlaying = true;
- this.$nextTick(() => {
- const videoContext = common_vendor.index.createVideoContext("myVideo", this);
- if (videoContext) {
- videoContext.play();
- }
- });
- } else {
- this.finishInterview();
- }
- return;
- }
- this.isPlayingLowScoreVideo = true;
- this.showStartRecordingButton = false;
- this.showStopRecordingButton = false;
- this.showRerecordButton = false;
- this.videoUrl = this.lowScoreVideoUrl;
- this.videoPlaying = true;
- const currentQuestion = this.getCurrentQuestionByIndex(this.currentVideoIndex);
- const originalSubtitle = currentQuestion ? currentQuestion.question || currentQuestion.question : this.currentSubtitle;
- this.currentSubtitle = "";
- this.$nextTick(() => {
- const videoContext = common_vendor.index.createVideoContext("myVideo", this);
- if (videoContext) {
- videoContext.play();
- setTimeout(() => {
- this.currentSubtitle = "我未听清楚您在说什么,请您再说一遍!";
- this.lowScoreVideoSubtitles = [
- {
- startTime: 0,
- endTime: 30,
- text: "我未听清楚您在说什么,请您再说一遍!",
- translation: "I didn't quite catch what you said, could you please repeat it?"
- }
- ];
- }, 500);
- }
- });
- this.originalQuestionSubtitle = originalSubtitle;
- },
- // 添加新方法:处理重新录制按钮点击
- handleRerecordButtonClick() {
- console.log("点击重新录制按钮");
- this.retryCount++;
- console.log(`当前重试次数: ${this.retryCount}/${this.maxRetryAttempts}`);
- this.showRerecordButton = false;
- this.handleStartRecordingClick();
- },
- // 页面卸载时关闭WebSocket连接
- onUnload() {
- console.log("页面卸载,关闭WebSocket连接");
- this.cleanupPersonDetectionWebSocket();
- this.stopUserCamera();
- this.clearCountdown();
- if (this.recordingTimer) {
- clearInterval(this.recordingTimer);
- this.recordingTimer = null;
- }
- if (this.mediaRecorder && this.mediaRecorder.state !== "inactive") {
- this.mediaRecorder.stop();
- }
- common_vendor.index.setKeepScreenOn({
- keepScreenOn: false
- });
- },
- // 页面隐藏时关闭WebSocket连接
- onHide() {
- console.log("页面隐藏,关闭WebSocket连接");
- this.cleanupPersonDetectionWebSocket();
- if (this.isRecording) {
- console.log("页面隐藏时正在录制,录制将继续");
- common_vendor.index.showToast({
- title: "请不要离开面试页面",
- icon: "none",
- duration: 2e3
- });
- }
- },
- // 页面显示时重新初始化WebSocket连接
- onShow() {
- console.log("identity-verify页面onShow");
- console.log("当前本地存储中的职位信息:", common_vendor.index.getStorageSync("selectedJob"));
- this.fetchQuestions();
- const systemInfo = common_vendor.index.getSystemInfoSync();
- const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith("mp-");
- if (isMiniProgram) {
- if (!this.personDetectionSocket) {
- console.log("重新初始化WebSocket连接");
- this.initPersonDetectionWebSocket();
- } else if (!this.personDetectionInterval) {
- console.log("重新启动人脸检测定时器");
- this.startPersonDetectionInterval();
- }
- }
- common_vendor.index.hideHomeButton();
- },
- // 添加新方法:阻止视频控制
- preventVideoControl(e) {
- e.preventDefault();
- e.stopPropagation();
- console.log("阻止视频控制操作");
- return false;
- },
- // 添加获取追问问题的方法
- fetchFollowUpQuestions() {
- const tenant_id = common_vendor.index.getStorageSync("tenant_id") || JSON.parse(common_vendor.index.getStorageSync("userInfo")).tenant_id || "1";
- let position_id = 1;
- try {
- const selectedJob = JSON.parse(common_vendor.index.getStorageSync("selectedJob") || "{}");
- if (selectedJob && selectedJob.id) {
- position_id = selectedJob.id;
- console.log("使用选择的职位ID获取追问问题:", position_id);
- } else {
- console.warn("未找到选择的职位信息,使用默认职位ID:", position_id);
- }
- } catch (e) {
- console.error("解析职位信息失败:", e);
- }
- const timestamp = Date.now();
- const requestUrl = `${common_config.apiBaseUrl}/api/wechat/open_questions/?position_id=${position_id}&tenant_id=${tenant_id}&question_form=5&_t=${timestamp}`;
- console.log("获取追问问题的请求URL:", requestUrl);
- common_vendor.index.request({
- url: requestUrl,
- method: "GET",
- success: (res) => {
- if (res.data && res.data.code === 2e3 && res.data.data && res.data.data.items) {
- console.log("获取追问问题数据成功:", res.data.data.items);
- this.followUpQuestions = res.data.data.items.map((item) => ({
- ...item,
- question_form: 5
- // 确保每个追问问题都有正确的question_form值
- }));
- this.processFollowUpQuestions();
- } else {
- console.error("获取追问问题数据失败:", res.data);
- this.followUpQuestions = [];
- }
- },
- fail: (err) => {
- console.error("请求追问问题数据失败:", err);
- this.followUpQuestions = [];
- }
- });
- },
- // 改进处理追问问题数据的方法
- processFollowUpQuestions() {
- if (!this.followUpQuestions || this.followUpQuestions.length === 0) {
- console.log("没有追问问题数据");
- this.followUpQuestions = [];
- return;
- }
- console.log("处理追问问题数据,总数:", this.followUpQuestions.length);
- this.followUpQuestions = this.followUpQuestions.filter((q) => q.parent_question_id);
- const parentQuestionIds = /* @__PURE__ */ new Set();
- this.followUpQuestions.forEach((question) => {
- if (question.parent_question_id) {
- parentQuestionIds.add(question.parent_question_id);
- }
- });
- console.log("有追问的父问题ID:", Array.from(parentQuestionIds));
- this.hasPlayedFollowUp = {};
- },
- // 修改检查并播放追问问题的方法
- checkAndPlayFollowUpQuestion(parentQuestionId) {
- console.log("检查是否有追问问题,父问题ID:", parentQuestionId);
- if (this.isWaitingForAnswer) {
- console.log("正在等待用户回答,暂不处理追问");
- return;
- }
- if (!parentQuestionId) {
- console.warn("没有父问题ID,无法检查追问问题");
- this.proceedToNextQuestion();
- return;
- }
- if (this.hasPlayedFollowUp[parentQuestionId]) {
- console.log("已经播放过此问题的追问,直接进入下一个问题");
- this.retryCount = 0;
- this.proceedToNextQuestion();
- return;
- }
- const followUpQuestion = this.followUpQuestions.find(
- (q) => q.parent_question_id === parentQuestionId && q.digital_human_video_url && q.question_form === 5
- );
- if (followUpQuestion) {
- console.log("找到追问问题:", followUpQuestion);
- const recordingDuration = this.getRecordingDuration();
- const lowScoreDuration = 7;
- const minDuration = 3;
- if (recordingDuration < lowScoreDuration) {
- let message = recordingDuration < minDuration ? `录制时间 ${recordingDuration} 秒,少于最小时长 ${minDuration} 秒` : `录制时间 ${recordingDuration} 秒,少于标准时长 ${lowScoreDuration} 秒`;
- console.log(message + ",将播放低分提示视频");
- this.retryCount++;
- this.needPlayLowScoreVideo = true;
- this.playLowScoreVideo();
- return;
- }
- this.retryCount = 0;
- this.hasPlayedFollowUp[parentQuestionId] = true;
- this.isFollowUpQuestion = true;
- this.currentParentQuestionId = parentQuestionId;
- this.currentFollowUpQuestion = followUpQuestion;
- this.playFollowUpQuestionVideo(followUpQuestion);
- } else {
- console.log("没有找到对应的追问问题,继续下一个问题");
- this.retryCount = 0;
- this.proceedToNextQuestion();
- }
- },
- // 修改播放追问问题视频的方法
- playFollowUpQuestionVideo(followUpQuestion) {
- console.log("播放追问问题视频:", followUpQuestion.digital_human_video_url);
- this.parentQuestion = this.currentSubtitle;
- this.videoUrl = followUpQuestion.digital_human_video_url;
- this.videoPlaying = true;
- this.isFollowUpQuestion = true;
- this.currentFollowUpQuestion = followUpQuestion;
- const followUpSubtitles = [{
- startTime: 0,
- endTime: 60,
- // 延长显示时间到60秒
- text: followUpQuestion.question || followUpQuestion.question
- }];
- const subtitleKey = `followUpSubtitles_${followUpQuestion.id}`;
- this[subtitleKey] = followUpSubtitles;
- this.$nextTick(() => {
- const videoContext = common_vendor.index.createVideoContext("myVideo", this);
- if (videoContext) {
- videoContext.play();
- this.currentSubtitle = followUpSubtitles[0].text;
- }
- });
- },
- // 添加作废面试的方法
- invalidateInterview() {
- if (this.isRecording) {
- this.stopRecordingAnswer();
- }
- if (this.recordingTimer) {
- clearInterval(this.recordingTimer);
- }
- this.isRecording = false;
- this.showStopRecordingButton = false;
- this.showStartRecordingButton = false;
- setTimeout(() => {
- common_vendor.index.switchTab({
- url: "/pages/index/index"
- });
- }, 500);
- },
- initPersonDetectionWebSocket() {
- if (this.personDetectionSocket) {
- this.cleanupPersonDetectionWebSocket();
- }
- console.log("YOLO分析开始");
- try {
- this.personDetectionSocket = common_vendor.index.connectSocket({
- url: `${common_config.personDetectionWsUrl}/ws/interview-room/room_${common_vendor.index.getStorageSync("appId")}/${common_vendor.index.getStorageSync("appId")}/`,
- success: () => {
- console.log("WebSocket connection initiated");
- },
- fail: (error) => {
- console.error("WebSocket connection failed:", error);
- }
- });
- this.personDetectionSocket.onOpen(() => {
- console.log("WebSocket connection opened");
- this.startPersonDetectionInterval();
- });
- this.personDetectionSocket.onError((error) => {
- console.error("WebSocket error:", error);
- this.cleanupPersonDetectionWebSocket();
- });
- this.personDetectionSocket.onClose(() => {
- console.log("WebSocket connection closed");
- this.cleanupPersonDetectionWebSocket();
- });
- this.personDetectionSocket.onMessage((res) => {
- try {
- const data = JSON.parse(res.data);
- if (data.type === "person_detection_result") {
- this.handlePersonDetectionResult(data);
- }
- } catch (error) {
- }
- });
- } catch (error) {
- console.error("Error initializing WebSocket:", error);
- this.cleanupPersonDetectionWebSocket();
- }
- },
- startPersonDetectionInterval() {
- if (this.personDetectionInterval) {
- clearInterval(this.personDetectionInterval);
- }
- this.personDetectionInterval = setInterval(() => {
- try {
- if (!this.personDetectionSocket || !this.cameraContext) {
- console.warn("人脸检测:相机上下文或WebSocket连接未就绪");
- return;
- }
- if (this.isRecording && this.useMiniProgramCameraComponent) {
- this.startFrameStreamCapture();
- } else {
- this.stopFrameStreamCapture();
- this.safeTakePhotoAndSend();
- }
- } catch (mainError) {
- console.error("人脸检测:主流程执行出错:", mainError);
- }
- }, this.frameCaptureIntervalMs || 5e3);
- },
- cleanupPersonDetectionWebSocket() {
- if (this.personDetectionInterval) {
- clearInterval(this.personDetectionInterval);
- this.personDetectionInterval = null;
- }
- if (this.personDetectionSocket) {
- try {
- this.personDetectionSocket.close();
- } catch (error) {
- console.error("Error closing WebSocket:", error);
- }
- this.personDetectionSocket = null;
- }
- },
- handlePersonDetectionResult(data) {
- if (data.data.identity.status == "no_face") {
- this.showPageWarning = true;
- common_vendor.index.showToast({
- /* data.data.identity.message */
- title: "请保持面部完整出现在镜头内",
- icon: "none",
- duration: 3e3
- });
- common_vendor.index.vibrateLong({
- success: function() {
- console.log("Vibration successful");
- },
- fail: function(err) {
- console.error("Vibration failed:", err);
- }
- });
- setTimeout(() => {
- this.showPageWarning = false;
- }, 3e3);
- } else if (data.data.identity.status == "multiple_faces") {
- this.showPageDRWarning = true;
- common_vendor.index.showToast({
- /* data.data.identity.message */
- title: "请保持独立面试环境",
- icon: "none",
- duration: 3e3
- });
- common_vendor.index.vibrateLong({
- success: function() {
- console.log("Vibration successful");
- },
- fail: function(err) {
- console.error("Vibration failed:", err);
- }
- });
- setTimeout(() => {
- this.showPageDRWarning = false;
- }, 3e3);
- }
- },
- // 进入追问模式
- enterFollowUpMode() {
- this.isFollowUpMode = true;
- this.mainQuestionIndex = this.currentVideoIndex;
- console.log("进入追问模式,保存主问题索引:", this.mainQuestionIndex);
- },
- // 修改 handleFollowUpQuestion 方法
- async handleFollowUpQuestion(questionData) {
- console.log("处理追问:", questionData);
- this.enterFollowUpMode();
- console.log("处理追问问题数据:", questionData);
- if (!questionData || !questionData.follow_up_voice_url || !questionData.follow_up_question) {
- console.error("追问数据不完整:", questionData);
- common_vendor.index.showToast({
- title: "获取追问数据失败",
- icon: "none"
- });
- return;
- }
- this.parentQuestion = questionData.original_question || "";
- let audioUrl = "";
- if (questionData.follow_up_voice_url.direct_url) {
- audioUrl = questionData.follow_up_voice_url.direct_url;
- } else if (questionData.follow_up_voice_url.file_url) {
- audioUrl = questionData.follow_up_voice_url.file_url;
- }
- if (!audioUrl.startsWith("http")) {
- audioUrl = common_config.apiBaseUrl + audioUrl;
- }
- console.log("处理后的音频URL:", audioUrl);
- const followUpQuestionObj = {
- id: Date.now(),
- question: questionData.follow_up_question.trim(),
- // 去除可能的空白字符
- audioUrl,
- originalQuestion: questionData.original_question,
- sessionId: questionData.session_id
- };
- console.log("创建的追问问题对象:", followUpQuestionObj);
- this.followUpQuestions.push(followUpQuestionObj);
- this.currentFollowUpIndex = this.followUpQuestions.length - 1;
- this.followUpQuestion = followUpQuestionObj.question;
- this.followUpAudioUrl = followUpQuestionObj.audioUrl;
- this.isFollowUpQuestion = true;
- this.currentFollowUpQuestion = followUpQuestionObj;
- this.showSubtitle(followUpQuestionObj.question, true);
- try {
- await this.playFollowUpAudio();
- console.log("音频播放完成,准备录制回答");
- this.prepareToAnswer(true, followUpQuestionObj);
- } catch (error) {
- console.error("音频播放失败:", error);
- this.prepareToAnswer(true, followUpQuestionObj);
- }
- },
- // 播放追问音频
- async playFollowUpAudio() {
- return new Promise((resolve, reject) => {
- console.log("开始播放追问音频, URL:", this.followUpAudioUrl);
- if (!this.followUpAudioUrl) {
- console.error("没有音频URL");
- reject(new Error("没有音频URL"));
- return;
- }
- common_vendor.index.showLoading({
- title: "思考中..."
- });
- this.stopAndDestroyAudio();
- try {
- const innerAudioContext = common_vendor.index.createInnerAudioContext();
- this.audioContext = innerAudioContext;
- innerAudioContext.autoplay = true;
- innerAudioContext.obeyMuteSwitch = false;
- innerAudioContext.volume = 1;
- innerAudioContext.onCanplay(() => {
- console.log("音频可以播放");
- common_vendor.index.hideLoading();
- this.isAudioPlaying = true;
- });
- innerAudioContext.onEnded(() => {
- console.log("追问音频播放完成");
- this.isAudioPlaying = false;
- resolve();
- setTimeout(() => {
- this.stopAndDestroyAudio();
- this.prepareToAnswer(true, this.currentFollowUpQuestion);
- }, 100);
- });
- innerAudioContext.onError((res) => {
- console.error("音频播放错误:", res);
- this.isAudioPlaying = false;
- common_vendor.index.hideLoading();
- common_vendor.index.showToast({
- title: "音频播放失败",
- icon: "none"
- });
- reject(res);
- this.stopAndDestroyAudio();
- });
- console.log("设置音频源:", this.followUpAudioUrl);
- innerAudioContext.src = this.followUpAudioUrl;
- } catch (error) {
- console.error("创建或播放音频失败:", error);
- this.isAudioPlaying = false;
- common_vendor.index.hideLoading();
- common_vendor.index.showToast({
- title: "音频播放失败",
- icon: "none"
- });
- this.stopAndDestroyAudio();
- reject(error);
- }
- });
- },
- // 停止并销毁音频
- stopAndDestroyAudio() {
- if (!this.audioContext) {
- return;
- }
- const ctx = this.audioContext;
- this.audioContext = null;
- try {
- if (this.isAudioPlaying) {
- ctx.stop();
- }
- } catch (error) {
- console.error("停止音频播放失败:", error);
- }
- try {
- ctx.destroy();
- } catch (error) {
- console.error("销毁音频实例失败:", error);
- }
- this.isAudioPlaying = false;
- },
- // 显示字幕
- showSubtitle(text, isFollowUp = true) {
- console.log("显示字幕:", text);
- this.subtitleText = text;
- this.showSubtitleText = true;
- this.isFollowUpQuestion = isFollowUp;
- this.$nextTick(() => {
- setTimeout(() => {
- this.showSubtitleText = false;
- }, 8e3);
- });
- },
- // 显示问题对话框
- showQuestionDialog() {
- if (this.followUpQuestion) {
- common_vendor.index.showModal({
- title: "追问问题",
- content: this.followUpQuestion,
- showCancel: false,
- success: () => {
- this.prepareToAnswer(true, this.followUpQuestions[this.currentFollowUpIndex]);
- }
- });
- }
- },
- // 显示面试官思考中loading
- showThinkingLoading() {
- this.isThinking = true;
- common_vendor.index.showLoading({
- title: "面试官正在思考中",
- mask: false
- });
- },
- // 隐藏面试官思考中loading
- hideThinkingLoading() {
- this.isThinking = false;
- common_vendor.index.hideLoading();
- if (this.thinkingTimer) {
- clearTimeout(this.thinkingTimer);
- this.thinkingTimer = null;
- }
- },
- // 处理视频完成
- handleVideoCompletion(jobId) {
- this.isVideoSwitching = false;
- if (jobId === 9) {
- common_vendor.index.navigateTo({
- url: "/pages/interview-question/interview-question",
- success: () => {
- console.log("成功跳转到interview-question页面");
- },
- fail: (err) => {
- console.error("跳转到interview-question页面失败:", err);
- common_vendor.index.redirectTo({
- url: "/pages/interview-question/interview-question",
- fail: (redirectErr) => {
- console.error("重定向到interview-question页面也失败:", redirectErr);
- common_vendor.index.navigateBack({
- delta: 1
- });
- }
- });
- }
- });
- } else {
- let configData = {};
- try {
- const configStr = common_vendor.index.getStorageSync("configData");
- if (configStr && configStr.trim()) {
- configData = JSON.parse(configStr);
- }
- } catch (error) {
- console.error("解析configData失败:", error);
- configData = {};
- }
- console.log("获取到的配置数据:", configData);
- const questionFormSwitches = (configData == null ? void 0 : configData.question_form_switches) || {};
- const hasChoiceQuestions = questionFormSwitches.enable_fill_blank || questionFormSwitches.enable_image_choice || questionFormSwitches.enable_multiple_choice || questionFormSwitches.enable_single_choice;
- const hasScoringQuestions = questionFormSwitches.enable_scoring_questions;
- const hasPostureDetection = configData == null ? void 0 : configData.enable_posture_check;
- const hasCandidateQuestions = questionFormSwitches.enable_candidate_questions;
- let targetUrl = "/pages/camera/camera";
- let pageName = "camera页面";
- console.log("当前配置数据:", hasScoringQuestions);
- if (hasChoiceQuestions || hasScoringQuestions) {
- targetUrl = "/pages/camera/camera";
- pageName = "camera页面";
- } else if (hasPostureDetection) {
- targetUrl = "/pages/posture-guide/posture-guide";
- pageName = "posture-guide页面";
- } else if (hasCandidateQuestions) {
- targetUrl = "/pages/interview-question/interview-question";
- pageName = "interview-question页面";
- } else {
- targetUrl = "/pages/success/success";
- pageName = "camera页面";
- }
- console.log("根据配置跳转到:", targetUrl, "配置项:", questionFormSwitches);
- common_vendor.index.navigateTo({
- url: targetUrl,
- success: () => {
- console.log(`成功跳转到${pageName}`);
- },
- fail: (err) => {
- console.error(`跳转到${pageName}失败:`, err);
- common_vendor.index.redirectTo({
- url: targetUrl,
- fail: (redirectErr) => {
- console.error(`重定向到${pageName}也失败:`, redirectErr);
- common_vendor.index.switchTab({
- url: targetUrl,
- fail: (switchErr) => {
- console.error("所有跳转方式都失败:", switchErr);
- common_vendor.index.navigateBack({
- delta: 1
- });
- }
- });
- }
- });
- }
- });
- }
- }
- },
- computed: {
- // 计算进度比例
- progressRatio() {
- return this.recordingTimerCount / this.maxRecordingTime;
- },
- // 右半圆旋转角度
- half1Turn() {
- if (this.progressRatio <= 0.5) {
- return this.progressRatio * 2 * 180;
- } else {
- return 180;
- }
- },
- // 左半圆旋转角度
- half2Turn() {
- if (this.progressRatio <= 0.5) {
- return 0;
- } else {
- return (this.progressRatio - 0.5) * 2 * 180;
- }
- },
- // 修改进度百分比的计算方式
- progressPercent() {
- return Math.min(Math.round(this.recordingTimerCount / this.maxRecordingTime * 100), 100);
- },
- // 添加总题数计算属性
- totalQuestions() {
- return this.questions.length || 5;
- }
- }
- };
- function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
- return common_vendor.e({
- a: $data.statusBarHeight + "px",
- b: $data.videoUrl,
- c: common_vendor.o((...args) => $options.handleVideoError && $options.handleVideoError(...args)),
- d: common_vendor.o((...args) => $options.handleVideoEnded && $options.handleVideoEnded(...args)),
- e: common_vendor.o((...args) => $options.handleTimeUpdate && $options.handleTimeUpdate(...args)),
- f: common_vendor.o((...args) => $options.preventVideoControl && $options.preventVideoControl(...args)),
- g: common_vendor.o((...args) => $options.preventVideoControl && $options.preventVideoControl(...args)),
- h: $data.showAnswerButton
- }, $data.showAnswerButton ? {
- i: common_vendor.o((...args) => $options.handleAnswerButtonClick && $options.handleAnswerButtonClick(...args))
- } : {}, {
- j: $data.currentSubtitle || $data.showSubtitleText && $data.subtitleText
- }, $data.currentSubtitle || $data.showSubtitleText && $data.subtitleText ? common_vendor.e({
- k: $data.currentVideoIndex > 0
- }, $data.currentVideoIndex > 0 ? {
- l: common_vendor.t($data.currentVideoIndex),
- m: common_vendor.t($options.totalQuestions)
- } : {}, {
- n: !$data.isFollowUpQuestion
- }, !$data.isFollowUpQuestion ? {
- o: common_vendor.t($data.currentSubtitle)
- } : {
- p: common_vendor.t($data.parentQuestion),
- q: common_vendor.t($data.subtitleText || $data.currentSubtitle)
- }) : {}, {
- r: $data.useMiniProgramCameraComponent
- }, $data.useMiniProgramCameraComponent ? {
- s: common_vendor.o((...args) => $options.handleCameraError && $options.handleCameraError(...args))
- } : {}, {
- t: $data.useMiniProgramCameraComponent
- }, $data.useMiniProgramCameraComponent ? {
- v: $data.frameCanvasWidth,
- w: $data.frameCanvasHeight
- } : {}, {
- x: $data.showPageWarning ? 1 : "",
- y: $data.loading
- }, $data.loading ? {} : {}, {
- z: $data.showDebugInfo
- }, $data.showDebugInfo ? common_vendor.e({
- A: $data.assistantResponse
- }, $data.assistantResponse ? {
- B: common_vendor.t($data.assistantResponse)
- } : {}, {
- C: $data.audioTranscript
- }, $data.audioTranscript ? {
- D: common_vendor.t($data.audioTranscript)
- } : {}, {
- E: common_vendor.f($data.processedResponses, (item, index, i0) => {
- return common_vendor.e({
- a: item.role
- }, item.role ? {
- b: common_vendor.t(item.role)
- } : {}, {
- c: item.transcript
- }, item.transcript ? {
- d: common_vendor.t(item.transcript)
- } : {}, {
- e: index
- });
- })
- }) : {}, {
- F: $data.showStopRecordingButton
- }, $data.showStopRecordingButton ? {
- G: common_vendor.o((...args) => $options.stopRecordingAnswer && $options.stopRecordingAnswer(...args))
- } : {}, {
- H: $data.isRecording
- }, $data.isRecording ? {
- I: common_vendor.t($data.recordingTimeDisplay),
- J: `conic-gradient(${$data.progressColor} ${$options.progressPercent}%, ${$data.progressBgColor} 0%)`
- } : {}, {
- K: $data.showStartRecordingButton
- }, $data.showStartRecordingButton ? {
- L: common_vendor.o((...args) => $options.handleStartRecordingClick && $options.handleStartRecordingClick(...args))
- } : {}, {
- M: $data.showRetryButton
- }, $data.showRetryButton ? {
- N: common_vendor.o((...args) => $options.retryVideoUpload && $options.retryVideoUpload(...args))
- } : {}, {
- O: $data.showCountdown
- }, $data.showCountdown ? {
- P: common_vendor.t($data.countdownValue)
- } : {}, {
- Q: $data.showRerecordButton
- }, $data.showRerecordButton ? {
- R: common_vendor.o((...args) => $options.handleRerecordButtonClick && $options.handleRerecordButtonClick(...args))
- } : {}, {
- S: $data.showPageWarning ? 1 : ""
- });
- }
- const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-464e78c6"]]);
- wx.createPage(MiniProgramPage);
|