| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- import {
- selectMerchant,
- queryStoreBranch,
- getImUser
- } from '@/commit/api.js'
- import {
- emConnect,
- } from '@/EaseIM/emApis';
- import loginStore from '@/store/modules/login.js';
-
-
- const {
- loginWithPassword
- } = emConnect();
-
- const setEMUserLoginInfosToStorage = (userId, token) => {
- const params = {
- key: `EM_LOGIN_INFOS`,
- data: {
- userId: userId,
- token: token
- },
- };
- uni.setStorage({
- ...params
- });
- }
-
- const loginWithUserId = async () => {
- let loginEaseIMId = uni.getStorageSync('im_userid')
- try {
- const res = await loginWithPassword(
- loginEaseIMId,
- uni.getStorageSync('im_pass')
- );
- loginStore.mutations['SET_LOGIN_USER_BASE_INFOS']({
- loginUserId: loginEaseIMId,
- });
- setEMUserLoginInfosToStorage(
- loginEaseIMId.toLowerCase(),
- res.accessToken
- //注意:res.accessToken
- );
- } catch (error) {
- console.log('>>>>>>', error);
- uni.showToast({
- title: '登录失败',
- icon: 'none',
- });
- } finally {
- loginEaseIMId = '';
- }
- }
-
- const llwFunc = async () => {
- //lww
- let storeStaff = uni.getStorageSync('storeStaff')
- if (storeStaff != null) {
- const res = await queryStoreBranch({
- id: storeStaff.department
- })
- if (res.data.status == 200) {
- uni.setStorageSync('jurisdiction', paramsData.jurisdiction);
- }
- } else {
- uni.setStorageSync('jurisdiction', [7, 9, 5, 3]);
- }
-
- // TODO 需要明确含义,目前逻辑是undifined
- let type;
-
- if (type == 1) {
- console.log('返回上一页')
- uni.navigateBack({
- delta: 1
- })
- } else {
- uni.switchTab({
- url: '../pages/cashier/index'
- });
- }
- }
-
- const readQuery = () => {
- const hash = window.location.hash; // 例如:#/?param1=value1¶m2=value2
-
- // 检查 hash 是否为空
- if (hash) {
- // 创建一个 URLSearchParams 实例
- const queryString = hash.split('?')[1]; // 获取 '?' 后面的部分
- const params = new URLSearchParams(queryString);
-
- return JSON.parse(decodeURIComponent(params.get('data')))
- }
- }
-
- const func = async () => {
- try {
- const paramsData = readQuery()
- if(!paramsData) {
- return;
- }
-
- console.log('%c [ 1. 读取url登录信息url参数 ]-4', 'font-size:13px; background:pink; color:#bf2c9f;', paramsData)
-
- const paramsData1 = {
- "storeStaff": null,
- "x_token": "MTYzMzYxODYzMjY4MTA0NTIwMjUtMDEtMDYgYXQgMjI6MDA6MDkgQ1NU",
- "user": {
- "uid": 16336,
- "wechat_user_id": "0",
- "ali_user_id": "0",
- "account": "18632681045",
- "real_name": "",
- "label_id": null,
- "group_id": "11",
- "nickname": "用户1045",
- "avatar": "https://app.bjtdba.com/uploads/logo.jpg",
- "phone": "18632681045",
- "now_score": null,
- "score": 0,
- "now_money": 0,
- "brokerage_price": 0,
- "admin_agent_rate": null,
- "locktime": null,
- "user_number": null,
- "im": 0,
- "im_uuid": null,
- "last_ip": "20.100.5.11",
- "identity": 5,
- "spreadUid": null,
- "user_type": "MP",
- "pwd": "$2y$10$XARVMD82YRAl9NMwzLcrKeSozdzlnUj7IXp2dvPGYGobzYFlf0j5K",
- "mer_id": 0,
- "spread_count": 0,
- "first_sign": 0
- }
- }
-
- uni.setStorageSync('userinfo', paramsData.user);
- uni.setStorageSync('authorization', paramsData.x_token);
- uni.setStorageSync('storeStaff', paramsData.storeStaff);
-
- // 用户状态判断
- const userInfoData = await selectMerchant({
- uid: paramsData.user.uid
- });
-
- console.log('%c [ 2. 获取用户信息 ]-4', 'font-size:13px; background:pink; color:#bf2c9f;', userInfoData)
-
- if(userInfoData.data.status === 200) {
- // 新逻辑
- uni.setStorageSync('selectmerchant', userInfoData.data.data);
- let storeStaff = uni.getStorageSync('storeStaff')
- console.log('%c [ storeStaff ]-4', 'font-size:13px; background:pink; color:#bf2c9f;', storeStaff, storeStaff != null)
- console.log('%c [ 本地存储用户信息 userInfo ]-4', 'font-size:13px; background:pink; color:#bf2c9f;', uni.getStorageSync('userinfo'))
- localStorage.setItem('aaa', '33333')
- console.log('读原生的', localStorage.getItem('aaa'))
-
- if (storeStaff) {
- queryStoreBranch({
- id: storeStaff.department
- }).then(res => {
- if (res.data.status == 200) {
- uni.setStorageSync('jurisdiction', res.data.data.jurisdiction);
- }
- })
- } else {
- uni.setStorageSync('jurisdiction', [7, 9, 5, 3]);
- }
- // uni.showToast({
- // title: res.data.message,
- // icon: "none"
- // })
- setTimeout(function() {
- console.log('%c [ 3. 获取用户信息成功,跳转页面 ]-4', 'font-size:13px; background:pink; color:#bf2c9f;')
- uni.switchTab({
- url: '../../cashier/index'
- });
- }, 700);
- }
-
-
-
-
- return;
- // 之前的逻辑
-
- uni.setStorageSync('selectmerchant', data.data.data);
-
- const {
- merchantIntention = {},
- } = userInfoData.data.data || {};
-
- uni.setStorage({
- key: 'myUsername',
- data: JSON.stringify(uni.getStorageSync('userinfo').uid),
- });
- uni.setStorage({
- key: 'mer_id',
- data: merchantIntention.mer_id,
- });
-
- if (userInfoData.data.status == 200) {
- uni.setStorageSync('selectmerchant', userInfoData.data.data);
-
- const imUserData = await getImUser({
- mer_id: uni.getStorageSync('mer_id'),
- });
- // actionEMReconnect();
- const {
- loginWithPassword
- } = emConnect();
- uni.setStorage({
- key: 'im_userid',
- data: imUserData.data.data.im_userid
- })
- uni.setStorage({
- key: 'im_pass',
- data: imUserData.data.data.im_pass
- })
- uni.setStorage({
- key: 'im_uuid',
- data: imUserData.data.data.im_uuid
- })
- //环信注册成功 登录
- if (imUserData.data.status == 200) {
- console.log('>>>>>>>>环信注册成功 登录')
- await loginWithUserId()
- }
-
-
-
- await llwFunc();
-
- }
- } catch (error) {
- console.error(error);
- //TODO handle the exception
- }
-
-
-
- }
- export default func;
|