/*
 * @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('插件调用export=====',config);
    isUpdate && wx.setStorageSync('config', config)
    if (config.token) wx.setStorageSync("sessionToken", config.token)
    if (config.userInfo) wx.setStorageSync("userInfo", config.userInfo)
    if (config.userLogin) wx.setStorageSync("userLogin", config.userLogin)
  },
  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)
        }
      })
    })
  }
}