setAuth.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. const app = getApp()
  2. Page({
  3. data: {
  4. authParams: null,
  5. authServiceCode: null
  6. },
  7. handleChange(e) {
  8. let { obj } = e.target.dataset;
  9. let value = e.detail.value;
  10. this.data[obj] = value;
  11. },
  12. saveCongfig() {
  13. try {
  14. app.data.authParams = JSON.parse(this.data.authParams);
  15. } catch (error) {
  16. my.showToast({
  17. type: 'fail',
  18. content: 'JSON格式有误',
  19. duration: 1500,
  20. });
  21. return;
  22. }
  23. app.data.authServiceCode = this.data.authServiceCode;
  24. my.showToast({
  25. type: 'success',
  26. content: '保存成功',
  27. duration: 1500,
  28. });
  29. my.navigateBack(1)
  30. },
  31. resetConfig() {
  32. app.data.authParams = my.getStorageSync({key: "defaultauthParams"}).data;
  33. app.data.authServiceCode = my.getStorageSync({key: "defaultauthServiceCode"}).data;
  34. this.update();
  35. my.showToast({
  36. type: 'success',
  37. content: '恢复成功',
  38. duration: 1500,
  39. });
  40. my.navigateBack(1)
  41. },
  42. update() {
  43. this.setData({
  44. authParams: JSON.stringify(app.data.authParams),
  45. authServiceCode: app.data.authServiceCode
  46. })
  47. },
  48. onLoad() {
  49. this.update();
  50. },
  51. });