about.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. const app = getApp()
  2. const cache = require('../../../js/cache')
  3. const appConfig = require('../../../config')
  4. const utils = require('../../../utils/util')
  5. const common = require('../../../common')
  6. Component({
  7. properties: {
  8. switchToLocalText: {
  9. type: String,
  10. value: utils.getSwitchToLocalStatus() ? "切换到线上使用" : "切换到本地使用"
  11. }
  12. },
  13. options: {
  14. addGlobalClass: true,
  15. },
  16. data: {
  17. starCount: 0,
  18. forksCount: 0,
  19. visitTotal: 0,
  20. switchToLocalText: utils.getSwitchToLocalStatus() ? "切换到线上使用" : "切换到本地使用"
  21. },
  22. methods: {
  23. clearData: function () {
  24. try {
  25. wx.clearStorageSync();
  26. app.toast("清除成功");
  27. } catch (e) {
  28. app.toast("清空失败");
  29. }
  30. },
  31. showQrcode() {
  32. wx.previewImage({
  33. urls: ['https://www.travelzs.com/static/images/donating-weixin.jpg'],
  34. current: 'https://www.travelzs.com/static/images/donating-weixin.jpg' // 当前显示图片的http链接
  35. })
  36. },
  37. switchToLocal: function(){
  38. var _this = this;
  39. app.syncRes = res => {
  40. if(res.code == 0) {
  41. var val = 0;
  42. if (!utils.getSwitchToLocalStatus()) {
  43. val = 1;
  44. }
  45. app.toast("同步成功~");
  46. wx.setStorageSync(appConfig.storeKeys.switchToLocal, val);
  47. _this.setData({
  48. "switchToLocalText": utils.getSwitchToLocalStatus() ? "切换到线上使用" : "切换到本地使用"
  49. });
  50. }else{
  51. app.warning("同步失败~");
  52. }
  53. }
  54. //如果用户未登录,要求用户先登录
  55. if (!utils.hasLogined() && !utils.getSwitchToLocalStatus()){
  56. app.warning("请登录后再切换,否则无法同步数据~");
  57. return;
  58. }
  59. if(utils.getSwitchToLocalStatus()) {
  60. wx.showModal({
  61. title: '温馨提示',
  62. content: '切换到线上后,数据将会在多台设备同步,点击确认将实时同步数据',
  63. success: function (item) {
  64. if (item.confirm) {
  65. cache.sync();
  66. }
  67. }
  68. })
  69. return;
  70. }
  71. wx.showModal({
  72. title: '温馨提示',
  73. content: '切换到本地后,只能保存数据到本地,如果需要多台设备同步,请实时同步数据',
  74. success: function(item){
  75. if(item.confirm){
  76. cache.sync();
  77. }
  78. }
  79. })
  80. },
  81. }
  82. })