Browse Source

bug修复

yuanmingze 1 tuần trước cách đây
mục cha
commit
d8a1d7673d

+ 7 - 3
src/components/auth/AuthInputItem.vue

@@ -26,12 +26,16 @@
         :class="{ visible: isFocused }"
         @touchstart.stop.prevent="clear"
       >
-        <wd-icon name="error-fill" size="28rpx" :color="CLEAR_ICON_COLOR" />
+        <wd-icon name="close-circle-fill" size="28rpx" :color="INPUT_ICON_COLOR" />
       </view>
 
       <!-- 密码显隐 -->
       <view v-if="passwordToggle" class="input-type-toggle" @click="togglePassword">
-        <wd-icon :name="isPassword ? 'view' : 'eye-close'" size="28rpx" :color="CLEAR_ICON_COLOR" />
+        <wd-icon
+          :name="isPassword ? 'eye-invisible' : 'eye'"
+          size="28rpx"
+          :color="INPUT_ICON_COLOR"
+        />
       </view>
 
       <!-- 右侧插槽(验证码按钮等) -->
@@ -82,7 +86,7 @@ const modelValue = defineModel<string>({
 })
 
 /* ---------- state ---------- */
-const CLEAR_ICON_COLOR = '#9CA3AF'
+const INPUT_ICON_COLOR = '#9CA3AF'
 
 const isFocused = ref(false)
 const isPassword = ref(true)

+ 8 - 4
src/pages-mine/record-info/index.vue

@@ -105,8 +105,8 @@
     />
 
     <wd-select-picker
+      ref="drugPickerRef"
       v-model="selectedDrugIds"
-      v-model:visible="drugPickerVisible"
       title="选择推广药品"
       :columns="drugOptions"
       filterable
@@ -150,6 +150,10 @@ interface AreaConfirmEvent {
   selectedOptions?: AreaOption[]
 }
 
+interface SelectPickerExpose {
+  open: () => void
+}
+
 const entTaxCode = ref('')
 const entName = ref('')
 const loading = ref(true)
@@ -158,7 +162,7 @@ const submitting = ref(false)
 const educationPickerVisible = ref(false)
 const majorPickerVisible = ref(false)
 const areaPickerVisible = ref(false)
-const drugPickerVisible = ref(false)
+const drugPickerRef = ref<SelectPickerExpose>()
 const areaPickerValue = ref<string | number>()
 
 const educationList = ref<DictItem[]>([])
@@ -258,7 +262,7 @@ const openAreaPicker = () => {
 
 const openDrugPicker = () => {
   if (showEmptyOptions(drugOptions.value, '暂无可选推广药品')) return
-  drugPickerVisible.value = true
+  drugPickerRef.value?.open()
 }
 
 const confirmEducation = (event: PickerConfirmEvent) => {
@@ -490,7 +494,7 @@ const decodeQueryValue = (value?: string): string => {
 
 .submit-section {
   position: fixed;
-  z-index: 20;
+  z-index: 5;
   left: 0;
   right: 0;
   bottom: 0;

+ 33 - 16
src/pages/information/index.vue

@@ -61,13 +61,14 @@
       </view>
 
       <!-- 积分包 -->
-      <view class="share-popup__field">
+      <view class="share-popup__field share-popup__field--package">
         <text class="share-popup__label">选择积分包</text>
 
         <view class="share-popup__picker">
           <wd-picker-view
             v-model="selectedPackageValues"
             :columns="sharePackageList"
+            :item-height="60"
             :visible-item-count="3"
             @pickstart="sharePickerScrolling = true"
             @pickend="sharePickerScrolling = false"
@@ -76,19 +77,21 @@
       </view>
 
       <!-- 转发按钮 -->
-      <button
-        class="share-popup__confirm"
-        hover-class="share-popup__confirm--hover"
-        open-type="share"
-        :disabled="!canSubmitShare"
-        :data-title="shareTarget?.title || ''"
-        :data-id="shareTarget?.id || ''"
-        :data-active-tab="shareTarget?.type || activeTab"
-        :data-package-id="selectedPackage?.value || ''"
-        :data-remark="shareRemark"
-      >
-        确认转发
-      </button>
+      <view class="share-popup__footer">
+        <button
+          class="share-popup__confirm"
+          hover-class="share-popup__confirm--hover"
+          open-type="share"
+          :disabled="!canSubmitShare"
+          :data-title="shareTarget?.title || ''"
+          :data-id="shareTarget?.id || ''"
+          :data-active-tab="shareTarget?.type || activeTab"
+          :data-package-id="selectedPackage?.value || ''"
+          :data-remark="shareRemark"
+        >
+          确认转发
+        </button>
+      </view>
     </view>
   </wd-popup>
 </template>
@@ -378,7 +381,7 @@ onShareAppMessage((res) => {
 .share-popup {
   box-sizing: border-box;
   width: 100%;
-  padding: 32rpx 32rpx max(24rpx, env(safe-area-inset-bottom));
+  padding: 32rpx 32rpx 24rpx;
   background: #fff;
 }
 
@@ -471,8 +474,14 @@ onShareAppMessage((res) => {
 /* -------------------------------------------------------------------------- */
 
 .share-popup__picker {
+  min-height: 180px;
   overflow: hidden;
   border-radius: 12rpx;
+  --wot-picker-view-column-item-height: 60px;
+}
+
+.share-popup__field--package {
+  margin-bottom: 0;
 }
 
 /* -------------------------------------------------------------------------- */
@@ -499,6 +508,14 @@ onShareAppMessage((res) => {
 /* Button */
 /* -------------------------------------------------------------------------- */
 
+.share-popup__footer {
+  position: sticky;
+  z-index: 1;
+  bottom: 0;
+  padding-top: 24rpx;
+  background: #fff;
+}
+
 .share-popup__confirm {
   display: flex;
   align-items: center;
@@ -506,7 +523,7 @@ onShareAppMessage((res) => {
   width: 100%;
   height: 88rpx;
   padding: 0;
-  margin: 8rpx 0 0;
+  margin: 0;
   color: #fff;
   font-size: 30rpx;
   font-weight: 600;

+ 26 - 4
src/pages/mine/index.vue

@@ -376,12 +376,34 @@ const handleCompanySelect = () => {
   handleCompanyShow.value = true
 }
 
-const handleCompanyConfirm = (index: number) => {
-  if (index !== userStore.currentUserInfoIndex) {
-    userStore.setCurrentUserInfoIndex(index)
+const handleCompanyConfirm = async (index: number) => {
+  if (index === userStore.currentUserInfoIndex) {
+    handleCompanyShow.value = false
+    return
   }
 
-  handleCompanyShow.value = false
+  const selectedUser = userStore.userInfoList[index]
+  if (!selectedUser) return
+
+  try {
+    const result = await userStore.changeWeiXinLogin({
+      code: selectedUser.userId,
+      phone: selectedUser.phone,
+    })
+
+    if (!result.success) {
+      uni.showToast({
+        title: result.message || '切换企业失败',
+        icon: 'none',
+      })
+      return
+    }
+
+    handleCompanyShow.value = false
+    await getInternalMsgCountUnread()
+  } catch (error) {
+    console.error('切换企业失败:', error)
+  }
 }
 
 const navigateToAuth = () => {

+ 17 - 2
src/services/modules/login/index.ts

@@ -1,9 +1,11 @@
 import http from '../../index'
 import type {
   AuthTokenRequest,
+  ChangeEnterpriseRequest,
   CheckBlacklistRequest,
   CheckBlacklistResponse,
   LoginRequest,
+  OAuthTokenResponse,
   UpdUserPwdRequest,
 } from './type'
 import type { UserInfoResponse } from './userInfo'
@@ -11,14 +13,14 @@ import type { UserInfoResponse } from './userInfo'
 //  账号密码校验
 export const getAuthTokenApi = (data: AuthTokenRequest) => {
   const passwordUrl = encodeURIComponent(data.password)
-  return http.postRaw(
+  return http.postRaw<OAuthTokenResponse>(
     `/auth/oauth/token?username=${data.username + '@mp'}&password=${passwordUrl}&grant_type=password&scope=server&mp=wechat`
   )
 }
 
 // 登录
 export const getTokenBySmsApi = (data: LoginRequest) => {
-  return http.postRaw(
+  return http.postRaw<OAuthTokenResponse>(
     `/auth/mobile/token/sms?code=${data.code}&mobile=SMS@${data.username}&grant_type=mobile`,
     {},
     {
@@ -27,6 +29,19 @@ export const getTokenBySmsApi = (data: LoginRequest) => {
     }
   )
 }
+
+// 切换企业并换取该企业对应的 token
+export const changeEntApi = (data: ChangeEnterpriseRequest) => {
+  return http.postRaw<OAuthTokenResponse>(
+    `/auth/mobile/token/smsForChangeEnt?drugEntId=${data.code}&mobile=SMS@${data.phone}&grant_type=changeEnt`,
+    {},
+    {
+      loading: true,
+      loadingText: '切换中...',
+    }
+  )
+}
+
 // 通过微信 code 获取用户信息
 export const getUserInfoByCodeApi = (wxCode: string, avatar?: string) => {
   return http.get<UserInfoResponse>(`/admin/api/getUserInfoByCode?code=${wxCode}&avatar=${avatar}`)

+ 18 - 0
src/services/modules/login/type.d.ts

@@ -3,6 +3,24 @@ export interface LoginRequest {
   code: string
 }
 
+export interface ChangeEnterpriseRequest {
+  code: string
+  phone: string
+}
+
+export interface OAuthTokenResponse {
+  access_token?: string
+  refresh_token?: string
+  token_type?: string
+  expires_in?: number
+  scope?: string
+  active?: boolean
+  license?: string
+  user_info?: Record<string, unknown>
+  msg?: string
+  message?: string
+}
+
 export interface AuthTokenRequest {
   username: string
   password: string

+ 43 - 3
src/stores/modules/user.ts

@@ -2,8 +2,14 @@ import { defineStore } from 'pinia'
 
 import { getWXLoginCode } from '@/lib/wechatService'
 
-import { checkBlacklistApi, getTokenBySmsApi, getUserInfoByCodeApi } from '@/services/modules/login'
+import {
+  changeEntApi,
+  checkBlacklistApi,
+  getTokenBySmsApi,
+  getUserInfoByCodeApi,
+} from '@/services/modules/login'
 import type {
+  ChangeEnterpriseRequest,
   CheckBlacklistRequest,
   LoginActionResult,
   LoginRequest,
@@ -91,7 +97,37 @@ export const useUserStore = defineStore('user', {
       }
     },
 
-    async getUserInfoByCode(): Promise<UserInfoItem | undefined> {
+    async changeWeiXinLogin(payload: ChangeEnterpriseRequest): Promise<LoginActionResult> {
+      const res = await changeEntApi(payload)
+
+      if (!res.access_token) {
+        return {
+          success: false,
+          message: res.msg || res.message || '切换企业失败',
+        }
+      }
+
+      this.access_token = res.access_token
+
+      const targetIndex = this.userInfoList.findIndex(
+        (item) => String(item.userId) === String(payload.code)
+      )
+      if (targetIndex >= 0) {
+        this.currentUserInfoIndex = targetIndex
+      }
+
+      // 新企业使用独立的业务状态,切换后重新获取
+      this.resetLivenessReminderShown()
+      this.resetPopupNotices()
+
+      await this.getUserInfoByCode(payload.code)
+
+      return {
+        success: true,
+      }
+    },
+
+    async getUserInfoByCode(preferredUserId?: string): Promise<UserInfoItem | undefined> {
       const wxRes = await getWXLoginCode()
       if (!wxRes?.code) return undefined
 
@@ -104,7 +140,11 @@ export const useUserStore = defineStore('user', {
 
       this.userInfoList = userInfoList
 
-      const index = this.currentUserInfoIndex ?? 0
+      const preferredIndex = preferredUserId
+        ? userInfoList.findIndex((item) => String(item.userId) === String(preferredUserId))
+        : -1
+      const index = preferredIndex >= 0 ? preferredIndex : (this.currentUserInfoIndex ?? 0)
+      this.currentUserInfoIndex = index
       const currentUserInfo = userInfoList[index]
 
       if (!currentUserInfo) {