exportToPlugin.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * @Author: 'warrior' 772238918@qq.com
  3. * @Date: 2024-05-30 15:59:43
  4. * @LastEditors: 'warrior' 772238918@qq.com
  5. * @LastEditTime: 2024-06-03 18:12:31
  6. * @FilePath: \nova-wapp\exportToPlugin.js
  7. * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  8. */
  9. const CONFIG = require("./config.js");
  10. let {
  11. appid,
  12. company,
  13. rootPage,
  14. } = CONFIG.default
  15. module.exports = {
  16. appid,
  17. company,
  18. rootPage,
  19. updateLocal(config, isUpdate) {
  20. console.log('插件调用export=====',config);
  21. isUpdate && wx.setStorageSync('config', config)
  22. if (config.token) wx.setStorageSync("sessionToken", config.token)
  23. if (config.userInfo) wx.setStorageSync("userInfo", config.userInfo)
  24. if (config.userLogin) wx.setStorageSync("userLogin", config.userLogin)
  25. },
  26. getCode() {
  27. return new Promise((resolve) => {
  28. wx.login({
  29. success: function (res) {
  30. if (res.code) {
  31. console.log(res.code);
  32. resolve(res.code)
  33. }
  34. },
  35. fail: function (err) {
  36. console.warn('小程序wx.login失败');
  37. resolve()
  38. }
  39. });
  40. })
  41. },
  42. restart(err) {
  43. console.log(err);
  44. wx.exitMiniProgram()
  45. },
  46. router(type, url = '/index') {
  47. switch (type) {
  48. case 'navigateBack':
  49. wx.navigateBack({
  50. delta: url || 1,
  51. fail: function () {
  52. wx.reLaunch({
  53. url: "/index",
  54. });
  55. },
  56. })
  57. break;
  58. case 'navigateTo':
  59. wx.navigateTo({
  60. url: url
  61. })
  62. break;
  63. case 'reLaunch':
  64. wx.reLaunch({
  65. url: url
  66. })
  67. break;
  68. case 'redirectTo':
  69. wx.redirectTo({
  70. url: url
  71. })
  72. break;
  73. default:
  74. break;
  75. }
  76. },
  77. // 获取本地存储文件大小
  78. getFileInfo(filePath) {
  79. return new Promise((result) => {
  80. wx.getFileInfo({
  81. filePath: filePath,
  82. success(res) {
  83. result(res.size)
  84. },
  85. fail(err) {
  86. result(0)
  87. }
  88. })
  89. })
  90. }
  91. }