| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- /*
- * @Author: 'warrior' 772238918@qq.com
- * @Date: 2024-05-30 15:59:43
- * @LastEditors: 'warrior' 772238918@qq.com
- * @LastEditTime: 2024-06-03 18:12:31
- * @FilePath: \nova-wapp\exportToPlugin.js
- * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
- */
- const CONFIG = require("./config.js");
- let {
- appid,
- company,
- rootPage,
- } = CONFIG.default
- module.exports = {
- appid,
- company,
- rootPage,
- updateLocal(config, isUpdate) {
- console.log('===========================================');
- console.log('======= 插件授权回调 =======');
- console.log('config:', config);
- console.log('isUpdate:', isUpdate);
- console.log('===========================================');
-
- isUpdate && wx.setStorageSync('config', config)
- if (config.token) {
- wx.setStorageSync("sessionToken", config.token)
- console.log('✅ 已保存 sessionToken');
- }
- if (config.userInfo) {
- wx.setStorageSync("userInfo", config.userInfo)
- console.log('✅ 已保存 userInfo');
- }
- if (config.userLogin) {
- wx.setStorageSync("userLogin", config.userLogin)
- console.log('✅ 已保存 userLogin:', config.userLogin);
- }
-
- // 授权成功后,自动返回首页
- if (config.userLogin && isUpdate) {
- console.log('🔄 授权成功,准备返回首页...');
-
- // 检查是否有待处理的跳转
- const pendingNavigation = wx.getStorageSync('pendingNavigation');
-
- // 延迟一下,确保数据保存完成
- setTimeout(() => {
- const pages = getCurrentPages();
- console.log('当前页面栈层数:', pages.length);
-
- if (pages.length > 1) {
- // 如果有上一页,返回上一页
- console.log('📱 返回上一页');
- wx.navigateBack({
- delta: 1,
- success: () => {
- console.log('✅ 返回成功');
-
- // 如果有待处理的跳转,触发跳转
- if (pendingNavigation) {
- console.log('🎯 检测到待处理的跳转:', pendingNavigation);
- wx.removeStorageSync('pendingNavigation');
-
- // 再延迟一下,确保页面已经返回并刷新
- setTimeout(() => {
- // 触发页面的跳转方法
- const currentPages = getCurrentPages();
- const currentPage = currentPages[currentPages.length - 1];
-
- if (currentPage && currentPage.selectComponent) {
- const homeComponent = currentPage.selectComponent('#home-component');
- if (homeComponent && homeComponent.navigateToConsultation) {
- console.log('✅ 触发咨询页面跳转');
- homeComponent.navigateToConsultation();
- } else {
- console.warn('⚠️ 未找到 home 组件或 navigateToConsultation 方法');
- }
- }
- }, 500);
- }
- },
- fail: (err) => {
- console.error('❌ 返回失败:', err);
- // 如果返回失败,重新加载首页
- wx.reLaunch({
- url: rootPage || '/nova-pbf/pages/index/index'
- });
- }
- });
- } else {
- // 如果没有上一页,重新加载首页
- console.log('📱 重新加载首页');
- wx.reLaunch({
- url: rootPage || '/nova-pbf/pages/index/index'
- });
- }
- }, 500);
- }
-
- console.log('===========================================');
- },
- getCode() {
- return new Promise((resolve) => {
- wx.login({
- success: function (res) {
- if (res.code) {
- console.log(res.code);
- resolve(res.code)
- }
- },
- fail: function (err) {
- console.warn('小程序wx.login失败');
- resolve()
- }
- });
- })
- },
- restart(err) {
- console.log(err);
- wx.exitMiniProgram()
- },
- router(type, url = '/index') {
- switch (type) {
- case 'navigateBack':
- wx.navigateBack({
- delta: url || 1,
- fail: function () {
- wx.reLaunch({
- url: "/index",
- });
- },
- })
- break;
- case 'navigateTo':
- wx.navigateTo({
- url: url
- })
- break;
- case 'reLaunch':
- wx.reLaunch({
- url: url
- })
- break;
- case 'redirectTo':
- wx.redirectTo({
- url: url
- })
- break;
- default:
- break;
- }
- },
- // 获取本地存储文件大小
- getFileInfo(filePath) {
- return new Promise((result) => {
- wx.getFileInfo({
- filePath: filePath,
- success(res) {
- result(res.size)
- },
- fail(err) {
- result(0)
- }
- })
- })
- }
- }
|