免密登录代码提交
This commit is contained in:
@@ -45,4 +45,6 @@ Route::group('v1/store', function () {
|
||||
Route::get('detail', 'app\store\controller\VendorController@detail'); // 获取供应商详情
|
||||
Route::post('order', 'app\store\controller\VendorController@createOrder'); // 创建订单
|
||||
});
|
||||
})->middleware(['jwt']);
|
||||
})->middleware(['jwt']);
|
||||
|
||||
Route::get('v1/store/login', 'app\store\controller\LoginController@index');
|
||||
@@ -2,9 +2,11 @@
|
||||
|
||||
namespace app\store\controller;
|
||||
|
||||
use app\common\util\JwtUtil;
|
||||
use think\Db;
|
||||
use think\Controller;
|
||||
|
||||
class LoginController extends BaseController
|
||||
class LoginController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
@@ -13,13 +15,26 @@ class LoginController extends BaseController
|
||||
return errorJson('缺少必要参数');
|
||||
}
|
||||
|
||||
$user = Db::name('user')->alias('u')
|
||||
->join('device_user du','u.id = du.userId and u.companyId = du.companyId')
|
||||
->join('device d','du.deviceId = d.id and u.companyId = du.companyId')
|
||||
->where(['d.deviceImei' => $deviceId,'u.deleteTime' => 0,'du.deleteTime' => 0,'d.deleteTime'=> 0 ])
|
||||
$user = Db::name('users')->alias('u')
|
||||
->field('u.*')
|
||||
->join('device_user du', 'u.id = du.userId and u.companyId = du.companyId')
|
||||
->join('device d', 'du.deviceId = d.id and u.companyId = du.companyId')
|
||||
->where(['d.deviceImei' => $deviceId, 'u.deleteTime' => 0, 'du.deleteTime' => 0, 'd.deleteTime' => 0])
|
||||
->find();
|
||||
$member = array_merge($user, [
|
||||
'lastLoginIp' => $this->request->ip(),
|
||||
'lastLoginTime' => time()
|
||||
]);
|
||||
|
||||
exit_data($user);
|
||||
// 生成JWT令牌
|
||||
$token = JwtUtil::createToken($user, 86400 * 30);
|
||||
$token_expired = time() + 86400 * 30;
|
||||
|
||||
$data = [
|
||||
'member' => $member,
|
||||
'token' => $token,
|
||||
'token_expired' => $token_expired
|
||||
];
|
||||
return successJson($data, '登录成功');
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
// API配置文件
|
||||
|
||||
// 基础配置
|
||||
export const BASE_URL = 'http://yishi.com'
|
||||
//export const BASE_URL = 'https://ckbapi.quwanzhi.com'
|
||||
//export const BASE_URL = 'http://yishi.com'
|
||||
export const BASE_URL = 'https://ckbapi.quwanzhi.com'
|
||||
|
||||
// 获取请求头
|
||||
const getHeaders = (options = {}) => {
|
||||
|
||||
@@ -17,5 +17,17 @@ export const authApi = {
|
||||
deviceId: deviceId || '' // 设备ID(仅APP端有值)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
// 免密登录
|
||||
// @param {string} deviceId - 设备ID
|
||||
noPasswordLogin: (deviceId) => {
|
||||
return request({
|
||||
url: '/v1/store/login',
|
||||
method: 'GET',
|
||||
data: {
|
||||
deviceId: deviceId || ''
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -61,6 +61,14 @@
|
||||
登录
|
||||
</view>
|
||||
|
||||
<!-- 免密登录按钮 -->
|
||||
<view
|
||||
class="no-password-login-btn"
|
||||
@tap="handleNoPasswordLogin"
|
||||
>
|
||||
免密登录
|
||||
</view>
|
||||
|
||||
<!-- 联系我们 -->
|
||||
<view class="contact-us" @tap="contactUs">
|
||||
联系我们
|
||||
@@ -243,6 +251,66 @@
|
||||
}
|
||||
},
|
||||
|
||||
// 处理免密登录
|
||||
async handleNoPasswordLogin() {
|
||||
// 检查设备ID是否存在
|
||||
if (!this.deviceId) {
|
||||
uni.showToast({
|
||||
title: '获取设备信息失败,请重试',
|
||||
icon: 'none'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
uni.showLoading({
|
||||
title: '免密登录中...',
|
||||
mask: true
|
||||
});
|
||||
|
||||
try {
|
||||
// 调用免密登录API
|
||||
const response = await authApi.noPasswordLogin(this.deviceId);
|
||||
|
||||
console.log('免密登录响应:', response);
|
||||
console.log('设备ID:', this.deviceId);
|
||||
|
||||
if (response.code === 200) {
|
||||
// 登录成功,缓存token信息
|
||||
const { token, member, token_expired } = response.data;
|
||||
|
||||
// 存储token信息
|
||||
uni.setStorageSync('token', token);
|
||||
uni.setStorageSync('member', JSON.stringify(member));
|
||||
uni.setStorageSync('token_expired', token_expired);
|
||||
|
||||
uni.showToast({
|
||||
title: '免密登录成功',
|
||||
icon: 'success'
|
||||
});
|
||||
|
||||
// 登录成功后跳转到对话页面
|
||||
setTimeout(() => {
|
||||
redirectToChat();
|
||||
}, 1500);
|
||||
} else {
|
||||
// 登录失败,显示错误信息
|
||||
uni.showToast({
|
||||
title: response.msg || '免密登录失败,请使用账号密码登录',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('免密登录失败:', err);
|
||||
uni.showToast({
|
||||
title: '网络异常,请稍后重试',
|
||||
icon: 'none'
|
||||
});
|
||||
} finally {
|
||||
uni.hideLoading();
|
||||
}
|
||||
},
|
||||
|
||||
// 打开协议
|
||||
openAgreement(type) {
|
||||
uni.showToast({
|
||||
@@ -371,6 +439,23 @@
|
||||
background-color: #4080ff;
|
||||
}
|
||||
|
||||
.no-password-login-btn {
|
||||
height: 44px;
|
||||
line-height: 44px;
|
||||
text-align: center;
|
||||
background-color: #fff;
|
||||
color: #4080ff;
|
||||
border: 1px solid #4080ff;
|
||||
border-radius: 22px;
|
||||
margin: 10px 0 20px;
|
||||
font-size: 16px;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.no-password-login-btn:active {
|
||||
background-color: #f0f5ff;
|
||||
}
|
||||
|
||||
.contact-us {
|
||||
text-align: center;
|
||||
color: #999;
|
||||
|
||||
Reference in New Issue
Block a user