diff --git a/env.js b/env.js index 2beac7a..92e1006 100644 --- a/env.js +++ b/env.js @@ -1,3 +1,3 @@ -export const BASE_URL = 'https://ye4s.wms.gztbyc.com/' //后台根域名 https://demo.shopro.top -export const API_URL = `${BASE_URL}/api/` //后台接口域名 +export const BASE_URL = 'http://192.168.11.56:6060' //后台根域名 https://demo.shopro.top +export const API_URL = `${BASE_URL}/system` //后台接口域名 export const IMG_URL = 'https://ye4s.file.gzxunren.com' //全局网络图片地址变量,css背景图片地址变量在uni.scss diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue index 6ea68cd..31bc129 100644 --- a/src/pages/index/index.vue +++ b/src/pages/index/index.vue @@ -1,48 +1,181 @@ diff --git a/src/pages/login/login.vue b/src/pages/login/login.vue index d8cfb45..9cf56ab 100644 --- a/src/pages/login/login.vue +++ b/src/pages/login/login.vue @@ -1,30 +1,71 @@ @@ -33,7 +74,14 @@ export default { data() { return { - loginMode: 'scan', + loginMode: 'account', + showPassword: false, + focusedField: '', + scanLoading: false, + scanClientCode: '', + scanCode: '', + scanQrImage: '', + scanStatus: '等待扫码...', form: { username: '', password: '', @@ -43,11 +91,71 @@ export default { methods: { switchMode(mode) { this.loginMode = mode + if (mode === 'scan' && !this.scanCode && !this.scanQrImage) { + this.handleScanLogin() + } + }, + togglePassword() { + this.showPassword = !this.showPassword + }, + clearField(field) { + this.form[field] = '' + this.focusedField = field + }, + handleFocus(field) { + this.focusedField = field + }, + handleBlur() { + this.focusedField = '' }, handleScanLogin() { - uni.showToast({ - title: '请接入扫码能力', - icon: 'none', + if (this.scanLoading) { + return + } + + this.scanLoading = true + this.scanStatus = '正在获取二维码...' + + const query = [`method=user.getLoginWechatCode`, `v=1.0`, `timestamp=${Date.now()}`] + if (this.scanClientCode) { + query.push(`clientCode=${encodeURIComponent(this.scanClientCode)}`) + } + + uni.request({ + url: `http://192.168.11.56:6060/system?${query.join('&')}`, + method: 'POST', + header: { + platform: 'workerstation', + project: 'warehouse', + }, + data: this.scanClientCode ? { clientCode: this.scanClientCode } : {}, + success: (res) => { + const body = res?.data || {} + const payload = body?.data || body?.result || body + + const clientCode = payload?.clientCode || body?.clientCode || '' + const qrImage = payload?.qrCodeUrl || payload?.qrcodeUrl || payload?.codeUrl || payload?.wechatCodeUrl || payload?.image || '' + const loginCode = payload?.loginWechatCode || payload?.wechatCode || payload?.qrCode || payload?.code || '' + + if (clientCode) { + this.scanClientCode = clientCode + } + + this.scanQrImage = qrImage || '' + this.scanCode = loginCode || '' + + if (this.scanQrImage || this.scanCode) { + this.scanStatus = '等待扫码...' + } else { + this.scanStatus = body?.message || body?.msg || '二维码获取失败' + } + }, + fail: () => { + this.scanStatus = '网络异常,请稍后重试' + }, + complete: () => { + this.scanLoading = false + }, }) }, handleAccountLogin() { @@ -59,9 +167,47 @@ export default { return } - uni.showToast({ - title: '登录请求已发起', - icon: 'none', + uni.request({ + url: `http://192.168.11.56:6060/system?method=user.login&v=1.0×tamp=${Date.now()}`, + method: 'POST', + header: { + accept: 'application/json, text/plain, */*', + platform: 'workerstation', + project: 'warehouse' + }, + data: { + username: this.form.username, + password: this.form.password, + }, + success: (res) => { + const body = res?.data || {} + const token = body?.token || body?.data?.token || body?.result?.token + + if (token) { + uni.setStorageSync('token', token) + uni.showToast({ + title: '登录成功', + icon: 'success', + }) + setTimeout(() => { + uni.reLaunch({ + url: '/pages/index/index', + }) + }, 300) + return + } + + uni.showToast({ + title: body?.msg || body?.message || '登录失败', + icon: 'none', + }) + }, + fail: () => { + uni.showToast({ + title: '网络异常,请稍后重试', + icon: 'none', + }) + }, }) }, }, @@ -71,11 +217,59 @@ export default { \ No newline at end of file