123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- // components/local/change-env/change-env.js
- // app.js
- import {
- login
- } from '../../../utils/http';
- Component({
- /**
- * 组件的属性列表
- */
- options: {
- addGlobalClass: true
- },
- properties: {
- visible: {
- type: Boolean,
- value: false,
- },
- },
- /**
- * 组件的初始数据
- */
- data: {
- inputVal: "",
- env: false,
- items: [{
- value: 'ijolijoli',
- name: '正式环境',
- checked: true
- },
- {
- value: 'dev',
- name: '测试环境',
- checked: false
- },
- ]
- },
- /**
- * 组件的方法列表
- */
- methods: {
- // 监听输入框
- onChangeInput(e) {
- this.setData({
- inputVal: e.detail.value
- })
- },
- // 点击确定事件
- onConfirm() {
- let {
- env,
- items
- } = this.data;
- if (env) {
- items.forEach((item, index) => {
- if (item.checked) {
- wx.setStorageSync('env', item.value)
- this.setData({
- visible: false,
- env: false,
- }, () => {
- login()
- wx.reLaunch({
- url: '/pages/home/home',
- })
- })
- }
- })
- return;
- }
- if (this.data.inputVal == 'ijolijoli') {
- this.setData({
- env: true
- })
- } else {
- wx.showToast({
- title: '密码错误',
- icon: 'none'
- })
- }
- console.log(this.data.inputVal)
- },
- // 点击取消事件
- onCancel() {
- this.setData({
- visible: false,
- env: false
- })
- },
- // 监听却换环境
- onChangeRadio(e) {
- console.log('radio发生change事件,携带value值为:', e.detail.value)
- const items = this.data.items
- for (let i = 0, len = items.length; i < len; ++i) {
- items[i].checked = items[i].value === e.detail.value
- }
- this.setData({
- items
- })
- },
- }
- })
|