change-env.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. this.setData({
  58. visible: false,
  59. env: false,
  60. }, () => {
  61. login()
  62. wx.reLaunch({
  63. url: '/pages/home/home',
  64. })
  65. })
  66. }
  67. })
  68. return;
  69. }
  70. if (this.data.inputVal == 'ijolijoli') {
  71. this.setData({
  72. env: true
  73. })
  74. } else {
  75. wx.showToast({
  76. title: '密码错误',
  77. icon: 'none'
  78. })
  79. }
  80. console.log(this.data.inputVal)
  81. },
  82. // 点击取消事件
  83. onCancel() {
  84. this.setData({
  85. visible: false,
  86. env: false
  87. })
  88. },
  89. // 监听却换环境
  90. onChangeRadio(e) {
  91. console.log('radio发生change事件,携带value值为:', e.detail.value)
  92. const items = this.data.items
  93. for (let i = 0, len = items.length; i < len; ++i) {
  94. items[i].checked = items[i].value === e.detail.value
  95. }
  96. this.setData({
  97. items
  98. })
  99. },
  100. }
  101. })