readAppInfo.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. import {
  2. selectMerchant,
  3. queryStoreBranch,
  4. getImUser
  5. } from '@/commit/api.js'
  6. import {
  7. emConnect,
  8. } from '@/EaseIM/emApis';
  9. import loginStore from '@/store/modules/login.js';
  10. const {
  11. loginWithPassword
  12. } = emConnect();
  13. const setEMUserLoginInfosToStorage = (userId, token) => {
  14. const params = {
  15. key: `EM_LOGIN_INFOS`,
  16. data: {
  17. userId: userId,
  18. token: token
  19. },
  20. };
  21. uni.setStorage({
  22. ...params
  23. });
  24. }
  25. const loginWithUserId = async () => {
  26. let loginEaseIMId = uni.getStorageSync('im_userid')
  27. try {
  28. const res = await loginWithPassword(
  29. loginEaseIMId,
  30. uni.getStorageSync('im_pass')
  31. );
  32. loginStore.mutations['SET_LOGIN_USER_BASE_INFOS']({
  33. loginUserId: loginEaseIMId,
  34. });
  35. setEMUserLoginInfosToStorage(
  36. loginEaseIMId.toLowerCase(),
  37. res.accessToken
  38. //注意:res.accessToken
  39. );
  40. } catch (error) {
  41. console.log('>>>>>>', error);
  42. uni.showToast({
  43. title: '登录失败',
  44. icon: 'none',
  45. });
  46. } finally {
  47. loginEaseIMId = '';
  48. }
  49. }
  50. const llwFunc = async () => {
  51. //lww
  52. let storeStaff = uni.getStorageSync('storeStaff')
  53. if (storeStaff != null) {
  54. const res = await queryStoreBranch({
  55. id: storeStaff.department
  56. })
  57. if (res.data.status == 200) {
  58. uni.setStorageSync('jurisdiction', paramsData.jurisdiction);
  59. }
  60. } else {
  61. uni.setStorageSync('jurisdiction', [7, 9, 5, 3]);
  62. }
  63. // TODO 需要明确含义,目前逻辑是undifined
  64. let type;
  65. if (type == 1) {
  66. console.log('返回上一页')
  67. uni.navigateBack({
  68. delta: 1
  69. })
  70. } else {
  71. uni.switchTab({
  72. url: '../pages/cashier/index'
  73. });
  74. }
  75. }
  76. const readQuery = () => {
  77. const hash = window.location.hash; // 例如:#/?param1=value1&param2=value2
  78. // 检查 hash 是否为空
  79. if (hash) {
  80. // 创建一个 URLSearchParams 实例
  81. const queryString = hash.split('?')[1]; // 获取 '?' 后面的部分
  82. const params = new URLSearchParams(queryString);
  83. return JSON.parse(decodeURIComponent(params.get('data')))
  84. }
  85. }
  86. const func = async () => {
  87. try {
  88. const paramsData = readQuery()
  89. if(!paramsData) {
  90. return;
  91. }
  92. const paramsData1 = {
  93. "storeStaff": null,
  94. "x_token": "MTYzMzYxODYzMjY4MTA0NTIwMjUtMDEtMDYgYXQgMjI6MDA6MDkgQ1NU",
  95. "user": {
  96. "uid": 16336,
  97. "wechat_user_id": "0",
  98. "ali_user_id": "0",
  99. "account": "18632681045",
  100. "real_name": "",
  101. "label_id": null,
  102. "group_id": "11",
  103. "nickname": "用户1045",
  104. "avatar": "https://app.bjtdba.com/uploads/logo.jpg",
  105. "phone": "18632681045",
  106. "now_score": null,
  107. "score": 0,
  108. "now_money": 0,
  109. "brokerage_price": 0,
  110. "admin_agent_rate": null,
  111. "locktime": null,
  112. "user_number": null,
  113. "im": 0,
  114. "im_uuid": null,
  115. "last_ip": "20.100.5.11",
  116. "identity": 5,
  117. "spreadUid": null,
  118. "user_type": "MP",
  119. "pwd": "$2y$10$XARVMD82YRAl9NMwzLcrKeSozdzlnUj7IXp2dvPGYGobzYFlf0j5K",
  120. "mer_id": 0,
  121. "spread_count": 0,
  122. "first_sign": 0
  123. }
  124. }
  125. uni.setStorageSync('userinfo', paramsData.user);
  126. uni.setStorageSync('authorization', paramsData.x_token);
  127. uni.setStorageSync('storeStaff', paramsData.storeStaff);
  128. // 用户状态判断
  129. const userInfoData = await selectMerchant({
  130. uid: paramsData.user.uid
  131. });
  132. console.log(userInfoData)
  133. const {
  134. merchantIntention = {},
  135. } = userInfoData.data.data || {};
  136. uni.setStorage({
  137. key: 'myUsername',
  138. data: JSON.stringify(uni.getStorageSync('userinfo').uid),
  139. });
  140. uni.setStorage({
  141. key: 'mer_id',
  142. data: merchantIntention.mer_id,
  143. });
  144. if (userInfoData.data.status == 200) {
  145. uni.setStorageSync('selectmerchant', userInfoData.data.data);
  146. const imUserData = await getImUser({
  147. mer_id: uni.getStorageSync('mer_id'),
  148. });
  149. // actionEMReconnect();
  150. const {
  151. loginWithPassword
  152. } = emConnect();
  153. uni.setStorage({
  154. key: 'im_userid',
  155. data: imUserData.data.data.im_userid
  156. })
  157. uni.setStorage({
  158. key: 'im_pass',
  159. data: imUserData.data.data.im_pass
  160. })
  161. uni.setStorage({
  162. key: 'im_uuid',
  163. data: imUserData.data.data.im_uuid
  164. })
  165. //环信注册成功 登录
  166. if (imUserData.data.status == 200) {
  167. console.log('>>>>>>>>环信注册成功 登录')
  168. await loginWithUserId()
  169. }
  170. await llwFunc();
  171. }
  172. } catch (error) {
  173. console.error(error);
  174. //TODO handle the exception
  175. }
  176. }
  177. export default func;