| | |
| | | <switch :checked='remberPassword' color="#FFCC33" style="zoom:.5" @change="remberChange" /> |
| | | </view> |
| | | </view> |
| | | <!-- <view class="button" @click="login" :loading="load.loading"> |
| | | {{load.btnText}} |
| | | </view> --> |
| | | <button class="button" @click="onLogin()" :loading="load.loading">{{load.btnText}}</button> |
| | | </view> |
| | | <!-- 设置弹窗区域 --> |
| | |
| | | <!-- 标题 --> |
| | | <view class="title">网 络 配 置</view> |
| | | <scroll-view scroll-y="true" class="settings-scroll"> |
| | | <view class="scroll-item" v-for="net in network"> |
| | | <view class="item-title" style="">{{net.name}}</view> |
| | | <view class="scroll-item"> |
| | | <view class="item-title" style="">{{network.name}}</view> |
| | | <view style="display: flex;align-items: center;"> |
| | | <input class="settings-input1" type="text" v-model="net.ip"> |
| | | <input class="settings-input1" type="text" v-model="network.ip"> |
| | | <text style="font-weight: 900;">:</text> |
| | | <input class="settings-input2" type="text" v-model="net.port"> |
| | | <input class="settings-input2" type="text" v-model="network.port"> |
| | | <text style="font-weight: 900;">/</text> |
| | | <input class="settings-input3" type="text" v-model="net.address"> |
| | | <input class="settings-input3" type="text" v-model="network.address"> |
| | | </view> |
| | | </view> |
| | | </scroll-view> |
| | |
| | | |
| | | <script> |
| | | // import { data } from 'jquery' |
| | | import { |
| | | mapState |
| | | } from 'vuex' //引入mapState |
| | | import { mapState } from 'vuex' //引入mapState |
| | | import store from '@/store/index.js'; |
| | | import md5 from '../../static/js/md5.js' |
| | | import common from '../api/common/common.js' |
| | | import login from '../api/login/login.js' |
| | | export default { |
| | | data() { |
| | | return { |
| | | version: '', |
| | | remberPassword: true, |
| | | user: { |
| | | username: '1', |
| | | password: '2' |
| | | username: '', |
| | | password: '' |
| | | }, |
| | | network: [{ |
| | | name: 'wms', |
| | | ip: '192.168.1.1', |
| | | port: '8080', |
| | | address: 'pswms' |
| | | }, |
| | | { |
| | | name: 'wcs', |
| | | ip: '192.168.1.1', |
| | | port: '9090', |
| | | address: 'pswcs' |
| | | } |
| | | ], |
| | | network: { |
| | | name: 'wms', |
| | | ip: '192.168.1.1', |
| | | port: '8080', |
| | | address: 'pswms' |
| | | }, |
| | | load: { |
| | | loading: false, |
| | | btnText: '登录' |
| | |
| | | } |
| | | }, |
| | | computed: mapState({ |
| | | project: state => state.project |
| | | project: state => state.project, |
| | | |
| | | }), |
| | | onShow() { |
| | | |
| | | }, |
| | | mounted() { |
| | | uni.getSystemInfo({ |
| | | success(res) { |
| | | // console.log(res); |
| | | } |
| | | }) |
| | | if (uni.getStorageSync('user')) { |
| | | this.user = uni.getStorageSync('user') |
| | | } |
| | | // 从 state 获取网络信息 |
| | | // 从 state 获取账号信息 |
| | | console.log(store.state); |
| | | this.user = store.state.userInfo |
| | | this.network = store.state.network |
| | | // 手机端版本号 |
| | | // #ifdef APP-PLUS |
| | | var that = this |
| | | var _this = this |
| | | plus.runtime.getProperty(plus.runtime.appid, function(wgtinfo) { |
| | | that.version = wgtinfo.version |
| | | _this.version = wgtinfo.version |
| | | }); |
| | | // #endif |
| | | }, |
| | | methods: { |
| | | remberChange() { |
| | | |
| | | this.remberPassword = !this.remberPassword |
| | | }, |
| | | settings() { |
| | | if (uni.getStorageSync('Network')) { |
| | | this.network = uni.getStorageSync('Network') |
| | | } |
| | | this.$refs.settings.open() |
| | | |
| | | }, |
| | | cancel() { |
| | | this.$refs.settings.close() |
| | | }, |
| | | confirm() { |
| | | uni.setStorageSync('Network', this.network); |
| | | let baseUrl = `http://${this.network.ip}:${this.network.port}/${this.network.address}` |
| | | this.$store.commit("setNetwork", this.network); |
| | | this.$store.commit("setBaseUrl", baseUrl); |
| | | this.$refs.settings.close() |
| | | }, |
| | | onLogin() { |
| | | let _this = this, |
| | | path = 'demo', |
| | | network = uni.getStorageSync('Network'); |
| | | if (!network) { |
| | | async onLogin() { |
| | | // 验证ip信息 |
| | | // 验证账号信息 |
| | | if (!this.user.username ) { |
| | | uni.showToast({ icon: 'none', title: '请输入账号' }) |
| | | return |
| | | } |
| | | if (!this.user.password ) { |
| | | uni.showToast({ icon: 'none', title: '请输入密码' }) |
| | | return |
| | | } |
| | | this.load.loading = true; |
| | | this.load.btnText = '登录中'; |
| | | let res = await login.onLogin(this.user) |
| | | if (res.code === 200) { |
| | | setTimeout(() => { |
| | | uni.showToast({ |
| | | title: '登录成功' |
| | | }) |
| | | setTimeout(() => { |
| | | uni.reLaunch({ |
| | | url: `/pages/home/home`, |
| | | }); |
| | | }, 300) |
| | | if (!this.remberPassword) { |
| | | this.user.password = '' |
| | | } |
| | | // uni.setStorageSync('user', this.user); |
| | | this.$store.commit("setUserInfo", this.user); |
| | | }, 700) |
| | | } else if (res.code === 0) { |
| | | this.load.loading = false; |
| | | this.load.btnText = '登录'; |
| | | uni.showToast({ |
| | | icon: 'error', |
| | | title: '请配置网络信息' |
| | | icon: 'none', |
| | | title: '连接失败,请检查设备网络/IP地址是否正确!' |
| | | }) |
| | | } else { |
| | | this.load.loading = false; |
| | | this.load.btnText = '登录'; |
| | | uni.showToast({ |
| | | icon: 'none', |
| | | title: `${this.user.username} ${res.msg}` |
| | | }) |
| | | } |
| | | // path = network[0].address |
| | | // path = path.substring(0, path.length - 3); |
| | | path = _this.project.name |
| | | let baseUrl = `http://${network[0].ip}:${network[0].port}/${network[0].address}` |
| | | _this.load.loading = true; |
| | | _this.load.btnText = '登录中'; |
| | | uni.setStorageSync('user', _this.user); |
| | | uni.request({ |
| | | url: `${baseUrl}/login.action`, |
| | | data: { |
| | | username: _this.user.username, |
| | | password: md5.hex_md5(_this.user.password) |
| | | }, |
| | | success(res) { |
| | | res = res.data |
| | | if (res.code === 200) { |
| | | uni.setStorageSync('token', res.data.token); |
| | | _this.load.btnText = '登录中'; |
| | | setTimeout(() => { |
| | | uni.showToast({ |
| | | title: '登录成功' |
| | | }) |
| | | setTimeout(() => { |
| | | uni.reLaunch({ |
| | | url: `/pages/home/home`, |
| | | }); |
| | | }, 300) |
| | | }, 700) |
| | | } |
| | | // uni.navigateTo({ |
| | | // url: `/pages/project/${path}/home/home`, |
| | | // fail(res) { |
| | | // console.log(`没有${path}项目,请联系管理元`); |
| | | // } |
| | | |
| | | // }) |
| | | } |
| | | }) |
| | | } |
| | | }, |
| | | } |
| | | } |
| | | </script> |