change-env.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // components/local/change-env/change-env.js
  2. // app.js
  3. import {
  4. login
  5. } from '../../../utils/http';
  6. Component({
  7. /**
  8. * 组件的属性列表
  9. */
  10. options: {
  11. addGlobalClass: true
  12. },
  13. properties: {
  14. visible: {
  15. type: Boolean,
  16. value: false,
  17. },
  18. },
  19. /**
  20. * 组件的初始数据
  21. */
  22. data: {
  23. inputVal: "",
  24. env: false,
  25. items: [{
  26. value: 'ijolijoli',
  27. name: '正式环境',
  28. checked: true
  29. },
  30. {
  31. value: 'dev',
  32. name: '测试环境',
  33. checked: false
  34. },
  35. ]
  36. },
  37. /**
  38. * 组件的方法列表
  39. */
  40. methods: {
  41. // 监听输入框
  42. onChangeInput(e) {
  43. this.setData({
  44. inputVal: e.detail.value
  45. })
  46. },
  47. // 点击确定事件
  48. onConfirm() {
  49. let {
  50. env,
  51. items
  52. } = this.data;
  53. if (env) {
  54. items.forEach((item, index) => {
  55. if (item.checked) {
  56. wx.setStorageSync('env', item.value)
  57. wx.setStorageSync('token', '')
  58. wx.setStorageSync('userInfo', {});
  59. this.setData({
  60. visible: false,
  61. env: false,
  62. }, () => {
  63. // login()
  64. wx.reLaunch({
  65. url: '/pages/home/home',
  66. })
  67. })
  68. }
  69. })
  70. return;
  71. }
  72. if (this.data.inputVal == 'ijolijoli') {
  73. this.setData({
  74. env: true
  75. })
  76. } else {
  77. wx.showToast({
  78. title: '密码错误',
  79. icon: 'none'
  80. })
  81. }
  82. console.log(this.data.inputVal)
  83. },
  84. // 点击取消事件
  85. onCancel() {
  86. this.setData({
  87. visible: false,
  88. env: false
  89. })
  90. },
  91. // 监听却换环境
  92. onChangeRadio(e) {
  93. console.log('radio发生change事件,携带value值为:', e.detail.value)
  94. const items = this.data.items
  95. for (let i = 0, len = items.length; i < len; ++i) {
  96. items[i].checked = items[i].value === e.detail.value
  97. }
  98. this.setData({
  99. items
  100. })
  101. },
  102. }
  103. })