2 lines
5.0 KiB
JavaScript
2 lines
5.0 KiB
JavaScript
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./common/vendor.js"),t=require("./utils/payment.js"),n=require("./config/api.js"),o=require("./utils/videoCacheManager.js");Math;const r={onLaunch(e){console.log("App Launch"),this.setupMpWeixinAuthGuard(),this.cleanVideoCache(),this.loadAppConfig(),this.loadServicePrices(),this.setupPaymentInterceptor(),this.getUserIdentity(),this.requestPermissions()},onShow(){console.log("App Show")},onHide(){console.log("App Hide")},methods:{setupMpWeixinAuthGuard(){const t=["/pages/login/login","/pages/settings/privacy-policy","/pages/settings/user-agreement","/pages/index/index"],n=["/pages/history/history","/pages/revival/revival-history","/pages/revival/revival","/pages/phone-call/phone-call","/pages/video-call/video-call","/pages/video-call-new/video-call-new","/pages/video-gen/video-gen","/pages/upload-audio/upload-audio","/pages/my-works/my-works","/pages/profile/edit-profile","/pages/settings/settings"],o=o=>{const r=(e=>{if(!e)return"";const t=e.indexOf("?"),n=t>=0?e.slice(0,t):e;return n.startsWith("/")?n:`/${n}`})(o);return!!r&&(!t.includes(r)&&(!!n.includes(r)&&!(()=>{const t=e.index.getStorageSync("token"),n=e.index.getStorageSync("userId");return!(!t||!n)})()))},r=t=>{const n=e.index[t];"function"==typeof n&&(e.index[t]=(t={})=>{try{const n="string"==typeof t?t:t.url;if(o(n)){const t=`/pages/login/login?redirect=${encodeURIComponent(n||"")}`;return e.index.reLaunch({url:t})}}catch(r){}return n.call(e.index,t)})};r("navigateTo"),r("redirectTo"),r("reLaunch"),r("switchTab")},cleanVideoCache(){try{const e=o.cleanExpiredCache(),t=o.cleanOldestCache();(e>0||t>0)&&console.log(`[App] 视频缓存清理完成:过期${e}个,旧缓存${t}个`)}catch(e){console.error("[App] 清理视频缓存失败:",e)}},async loadAppConfig(){try{e.index.removeStorageSync("appConfig"),console.log("[App] 缓存已清除,重新加载配置");const t=await e.index.request({url:`${n.API_BASE}${n.API_ENDPOINTS.config.getAppConfig}`,method:"GET",header:{"Content-Type":"application/json"}}),o=Array.isArray(t)?t[1]:t;if(o&&o.data&&o.data.success&&o.data.data){const t=o.data.data;e.index.setStorageSync("appConfig",t),console.log("[App] 应用配置已加载:",t)}}catch(t){console.error("[App] 加载应用配置失败:",t)}},async loadServicePrices(){try{await t.fetchServicePrices(),console.log("[App] 服务价格已加载")}catch(e){console.error("[App] 加载服务价格失败:",e)}},async getUserIdentity(){const t=e.index.getStorageSync("wx_openid");if(t)console.log("[App] 已有微信openid:",t);else try{const t=await e.index.login();if(t[1]&&t[1].code){const n=t[1].code;console.log("[App] 微信登录成功,code:",n),console.warn("[App] 使用模拟openid,生产环境需要实现后端接口"),e.index.setStorageSync("wx_openid","test_openid_"+Date.now())}}catch(n){console.error("[App] 获取微信openid失败:",n)}},setupPaymentInterceptor(){const n=n=>{try{if(!(()=>{const t=e.index.getStorageSync("token")||"",n=e.index.getStorageSync("userId")||"";return!(!t||!n)})())return void e.index.showModal({title:"提示",content:"请先登录后再继续",confirmText:"去登录",cancelText:"取消",success:t=>{t.confirm&&e.index.reLaunch({url:"/pages/login/login"})}});const r=n||t.SERVICE_TYPES.PHOTO_REVIVAL.type;let i=this;try{const e="function"==typeof getCurrentPages?getCurrentPages():[],t=e&&e.length?e[e.length-1]:null;t&&t.$vm&&(i=t.$vm)}catch(o){}t.showPaymentModal(i,r)}catch(o){console.error("[Payment] 402拦截弹窗失败:",o)}},o=(e,o)=>{try{const i=e&&e.url?e.url:"";let s=null;try{s=o&&"string"==typeof o.data?JSON.parse(o.data):o?o.data:null}catch(r){s=null}const a=s&&(s.serviceType||s.service_type),c=("CREATE_VOICE"===a?t.SERVICE_TYPES.VOICE_CLONE.type:"PHOTO_REVIVAL"===a?t.SERVICE_TYPES.PHOTO_REVIVAL.type:"VOLCENGINE_VIDEO"===a?t.SERVICE_TYPES.VOLCENGINE_VIDEO?t.SERVICE_TYPES.VOLCENGINE_VIDEO.type:"":"SYNTHESIZE"===a?t.SERVICE_TYPES.TTS_SYNTHESIS.type:"VIDEO_CALL"===a?t.SERVICE_TYPES.VIDEO_CALL.type:"AI_CALL"===a?t.SERVICE_TYPES.CONVERSATION.type:"")||(e=>{const n=String(e||"");return n.includes("/api/photo-revival/")?t.SERVICE_TYPES.PHOTO_REVIVAL.type:n.includes("/api/voice/")?t.SERVICE_TYPES.VOICE_CLONE.type:n.includes("/api/tts/")?t.SERVICE_TYPES.TTS_SYNTHESIS.type:n.includes("/api/video-call")?t.SERVICE_TYPES.VIDEO_CALL.type:n.includes("/api/conversation/")?t.SERVICE_TYPES.CONVERSATION.type:""})(i);n(c)}catch(r){console.error("[Payment] 402拦截处理失败:",r)}},r=t=>{let n=null;e.index.addInterceptor(t,{invoke:e=>(n=e,e),returnValue(e){try{if(e&&"function"==typeof e.then)return e.then((e=>{try{const t=Array.isArray(e)?e[1]:e;t&&402===t.statusCode&&o(n,t)}catch(t){}return e}));const t=Array.isArray(e)?e[1]:e;if(t&&402===t.statusCode){const r=Array.isArray(e)?e[0]:n;o(r,t)}}catch(t){}return e}})};r("request"),r("uploadFile")},async requestPermissions(){}}};function i(){const t=e.createSSRApp(r);return t.config.globalProperties.$apiBase=n.API_BASE,{app:t}}i().app.mount("#app"),exports.createApp=i;
|