Files
klp-mono/apps/hand-factory/api/login.js
2026-01-15 20:18:37 +08:00

106 lines
2.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import request from '@/utils/request'
import errorCode from '@/utils/errorCode'
import { toast, tansParams } from '@/utils/common'
// 登录方法
export function login(username, password, code, uuid) {
const data = {
username,
password,
code,
uuid
}
return request({
'url': '/login',
headers: {
isToken: false
},
'method': 'post',
'data': data
})
}
// Zinc1系统登录方法直接使用uni.request因为登录接口不需要token完全静默处理
export function loginZinc1(username, password, code, uuid) {
const data = {
username,
password,
code,
uuid
}
const baseUrl = 'http://140.143.206.120:10082/prod-api'
const timeout = 10000
return new Promise((resolve, reject) => {
uni.request({
method: 'post',
timeout: timeout,
url: baseUrl + '/login',
data: data,
header: {
'Content-Type': 'application/json'
},
dataType: 'json'
}).then(response => {
let [error, res] = response
if (error) {
// 静默失败,不显示任何提示
reject('Zinc1系统连接异常')
return
}
const code = res.data.code || 200
if (code === 200 && res.data && res.data.token) {
// 只有成功时才resolve
resolve(res.data)
} else {
// 其他情况静默失败
reject('Zinc1登录失败')
}
}).catch(error => {
// 静默失败,不显示任何提示
reject(error)
})
})
}
// 注册方法
export function register(data) {
return request({
url: '/register',
headers: {
isToken: false
},
method: 'post',
data: data
})
}
// 获取用户详细信息
export function getInfo() {
return request({
'url': '/getInfo',
'method': 'get'
})
}
// 退出方法
export function logout() {
return request({
'url': '/logout',
'method': 'post'
})
}
// 获取验证码
export function getCodeImg() {
return request({
'url': '/captchaImage',
headers: {
isToken: false
},
method: 'get',
timeout: 20000
})
}