登陆授权流程调整

This commit is contained in:
wangdongbo 2026-01-21 13:37:54 +08:00
parent c9df1e6341
commit f6b504a2bd
9 changed files with 392 additions and 380 deletions

218
App.vue
View File

@ -1,351 +1,353 @@
<script>
import useAccountStore from "@/store/account.js";
export default {
onLaunch: function () {
console.log('App Launch: ')
},
onShow: function () {
console.log('App Show')
},
onHide: function () {
console.log('App Hide')
}
}
onLaunch: function () {
// pinia store getActivePinia
const { login } = useAccountStore();
login();
console.log("App Launch: ");
},
onShow: function () {
console.log("App Show");
},
onHide: function () {
console.log("App Hide");
},
};
</script>
<style lang="scss">
$primary-color: #0074ff;
page {
height: 100%;
background: #f5f5f5;
height: 100%;
background: #f5f5f5;
}
.shadow-up {
box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px, rgba(0, 0, 0, 0) 0px 0px 0px 0px,
rgba(0, 0, 0, 0.1) 0px -10px 15px -3px, rgba(0, 0, 0, 0.1) 0px -4px 6px -4px;
box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px, rgba(0, 0, 0, 0) 0px 0px 0px 0px,
rgba(0, 0, 0, 0.1) 0px -10px 15px -3px, rgba(0, 0, 0, 0.1) 0px -4px 6px -4px;
}
.shadow-lg {
box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}
.relative {
position: relative;
position: relative;
}
.inline-block {
display: inline-block;
display: inline-block;
}
.flex {
display: flex;
display: flex;
}
.flex-col {
flex-direction: column;
flex-direction: column;
}
.flex-wrap {
flex-wrap: wrap;
flex-wrap: wrap;
}
.flex-grow {
flex-grow: 1;
flex-grow: 1;
}
.flex-shrink-0 {
flex-shrink: 0;
flex-shrink: 0;
}
.items-center {
align-items: center;
align-items: center;
}
.justify-center {
justify-content: center;
justify-content: center;
}
.justify-between {
justify-content: space-between;
justify-content: space-between;
}
.justify-around {
justify-content: space-around;
justify-content: space-around;
}
.justify-end {
justify-content: flex-end;
justify-content: flex-end;
}
.bg-gray {
background: #f5f5f5;
background: #f5f5f5;
}
.bg-primary {
background: $primary-color;
background: $primary-color;
}
.bg-success {
background: green;
background: green;
}
.bg-white {
background: #fff;
background: #fff;
}
.bg-warning {
background: orange;
background: orange;
}
.bg-danger {
background: rgb(248 113 113);
background: rgb(248 113 113);
}
.py-5 {
padding-top: 10rpx;
padding-bottom: 10rpx;
padding-top: 10rpx;
padding-bottom: 10rpx;
}
.p-15 {
padding: 30rpx;
padding: 30rpx;
}
.p-10 {
padding: 20rpx;
padding: 20rpx;
}
.px-5 {
padding-left: 10rpx;
padding-right: 10rpx;
padding-left: 10rpx;
padding-right: 10rpx;
}
.px-10 {
padding-left: 20rpx;
padding-right: 20rpx;
padding-left: 20rpx;
padding-right: 20rpx;
}
.px-12 {
padding-left: 24rpx;
padding-right: 24rpx;
padding-left: 24rpx;
padding-right: 24rpx;
}
.px-15 {
padding-left: 30rpx;
padding-right: 30rpx;
padding-left: 30rpx;
padding-right: 30rpx;
}
.pt-5 {
padding-top: 10rpx;
padding-top: 10rpx;
}
.pt-15 {
padding-top: 30rpx;
padding-top: 30rpx;
}
.break-all {
word-break: break-all;
word-break: break-all;
}
.pb-5 {
padding-bottom: 10rpx;
padding-bottom: 10rpx;
}
.pb-10 {
padding-bottom: 20rpx;
padding-bottom: 20rpx;
}
.py-10 {
padding-top: 20rpx;
padding-bottom: 20rpx;
padding-top: 20rpx;
padding-bottom: 20rpx;
}
.py-12 {
padding-top: 24rpx;
padding-bottom: 24rpx;
padding-top: 24rpx;
padding-bottom: 24rpx;
}
.py-15 {
padding-top: 30rpx;
padding-bottom: 30rpx;
padding-top: 30rpx;
padding-bottom: 30rpx;
}
.mr-5 {
margin-right: 10rpx;
margin-right: 10rpx;
}
.mr-10 {
margin-right: 20rpx;
margin-right: 20rpx;
}
.ml-15 {
margin-left: 30rpx;
margin-left: 30rpx;
}
.mb-5 {
margin-bottom: 10rpx;
margin-bottom: 10rpx;
}
.mb-10 {
margin-bottom: 20rpx;
margin-bottom: 20rpx;
}
.mt-10 {
margin-top: 20rpx;
margin-top: 20rpx;
}
.mt-15 {
margin-top: 30rpx;
margin-top: 30rpx;
}
.mt-12 {
margin-top: 24rpx;
margin-top: 24rpx;
}
.mx-10 {
margin-left: 20rpx;
margin-right: 20rpx;
margin-left: 20rpx;
margin-right: 20rpx;
}
.mx-auto {
margin-left: auto;
margin-right: auto;
margin-left: auto;
margin-right: auto;
}
.rounded {
border-radius: 16rpx;
border-radius: 16rpx;
}
.rounded-sm {
border-radius: 8rpx;
border-radius: 8rpx;
}
.rounded-full {
border-radius: 999px;
border-radius: 999px;
}
.text-center {
text-align: center;
text-align: center;
}
.text-right {
text-align: right;
text-align: right;
}
.text-gray {
color: #999;
color: #999;
}
.text-black {
color: #000;
color: #000;
}
.text-dark {
color: #333;
color: #333;
}
.text-danger {
color: #f56c6c;
color: #f56c6c;
}
.text-primary {
color: $primary-color;
color: $primary-color;
}
.text-success {
color: #67c23a;
color: #67c23a;
}
.text-white {
color: #fff;
color: #fff;
}
.text-warning {
color: #f56c6c;
color: #f56c6c;
}
.text-sm {
font-size: 24rpx;
font-size: 24rpx;
}
.text-base {
font-size: 28rpx;
font-size: 28rpx;
}
.text-lg {
font-size: 32rpx;
font-size: 32rpx;
}
.text-xl {
font-size: 36rpx;
font-size: 36rpx;
}
.leading-normal {
line-height: 1.5;
line-height: 1.5;
}
.border {
border: 1px solid #eee;
border: 1px solid #eee;
}
.border-dashed {
border: 1px dashed #eee;
border: 1px dashed #eee;
}
.border-b {
border-bottom: 1px solid #eee;
border-bottom: 1px solid #eee;
}
.border-auto {
border: 1px solid;
border: 1px solid;
}
.border-dashed-auto {
border: 1px dashed;
border: 1px dashed;
}
.border-primary {
border: 1px solid $primary-color;
border: 1px solid $primary-color;
}
.font-semibold {
font-weight: bold;
font-weight: bold;
}
.truncate {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.w-0 {
width: 0;
width: 0;
}
.w-full {
width: 100%;
width: 100%;
}
.overflow-hidden {
overflow: hidden;
overflow: hidden;
}
.border-box {
box-sizing: border-box;
box-sizing: border-box;
}
.line-clamp-2 {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
overflow: hidden;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
overflow: hidden;
}
.h-full {
height: 100%;
height: 100%;
}
.safe-bottom-padding {
height: env(safe-area-inset-bottom);
height: env(safe-area-inset-bottom);
}
</style>

View File

@ -1,38 +0,0 @@
const env = __VITE_ENV__;
/**
* 上传文件图片等
* zdh-hlw-patient /file/upload 接口保持一致
*/
export function uploadFile(tempFilePath, businessType, accessLevel = 'public') {
return new Promise((resolve) => {
uni.uploadFile({
url: `${env.MP_API_BASE_URL}/file/upload`,
filePath: tempFilePath,
name: 'file',
formData: {
businessType,
accessLevel,
},
success: (res) => {
try {
const data = typeof res.data === 'string' ? JSON.parse(res.data) : res.data;
if (data && data.success) {
resolve(data.data);
} else {
resolve();
}
} catch (e) {
console.log('upload file parse error:', e);
resolve();
}
},
fail: (err) => {
console.log('upload file error:', err);
resolve();
},
});
});
}

View File

@ -112,7 +112,6 @@ onLoad((opts) => {
console.log("redirectUrl", redirectUrl.value);
return;
}
// redirect useGuard redirectUrl
if (opts.redirect) {
redirectUrl.value = decodeURIComponent(opts.redirect);
} else {

View File

@ -1,45 +1,49 @@
<template>
<view class="dept-page">
<view class="dept-container bg-white">
<scroll-view class="sidebar" scroll-y>
<view
v-for="item in level1List"
:key="item._id"
:class="[
'sidebar-item',
item._id === selectedParentId ? 'active' : '',
]"
@click="selectParent(item)"
>
<text class="sidebar-text">{{ item.hlwDeptName }}</text>
<view class="sidebar">
<view class="sidebar-search">
<input
v-model="keyword"
class="search-input"
type="text"
confirm-type="search"
placeholder="搜索一级科室"
placeholder-class="search-placeholder"
/>
<view v-if="keyword" class="clear-btn" @click="keyword = ''"
>清空</view
>
</view>
</scroll-view>
<scroll-view class="sidebar-list" scroll-y>
<view
v-for="item in filteredLevel1List"
:key="item.deptId"
:class="[
'sidebar-item',
item.deptId === selectedParentId ? 'active' : '',
]"
@click="selectParent(item)"
>
<text class="sidebar-text">{{
item.hlwDeptName || item.deptName
}}</text>
</view>
</scroll-view>
</view>
<scroll-view class="content" scroll-y>
<view v-if="contentList.length" class="content-list">
<view
v-for="child in contentList"
:key="child._id"
:key="child.deptId"
:class="['dept-item', isSelected(child) ? 'selected' : '']"
@click="selectDept(child)"
>
<view class="dept-name-row" @click="selectDept(child)">
<view class="dept-name-row">
<view class="dept-name">{{ child.deptName }}</view>
<text v-if="isSelected(child)" class="check-tag">已选</text>
</view>
<view
v-if="child.children && child.children.length"
class="dept-sub-list"
>
<view
v-for="sub in child.children"
:key="sub._id"
:class="['dept-sub-item', isSelected(sub) ? 'selected' : '']"
@click.stop="selectDept(sub)"
>
<text class="dept-sub-text">{{ sub.deptName }}</text>
<text v-if="isSelected(sub)" class="check-dot" />
</view>
</view>
</view>
</view>
<view v-else class="empty-wrapper">
@ -47,16 +51,20 @@
</view>
</scroll-view>
</view>
<view class="footer-tip">
如没有符合的内容请联系客服
<text class="link" @click="contactService">点击添加客服</text>
</view>
</view>
</template>
<script setup>
import { computed, ref } from "vue";
import { computed, ref, watch } from "vue";
import { onLoad } from "@dcloudio/uni-app";
import { storeToRefs } from "pinia";
import useGuard from "@/hooks/useGuard.js";
import useAccountStore from "@/store/account.js";
import EmptyData from "@/components/empty-data.vue";
import api from "@/utils/api";
import { toast } from "@/utils/widget";
@ -66,6 +74,7 @@ const { useLoad } = useGuard();
const deptList = ref([]);
const selectedParentId = ref("");
const selectedDeptId = ref("");
const keyword = ref("");
const sorter = (a, b) => {
const sortA = typeof a.sort === "number" ? a.sort : 0;
@ -80,6 +89,14 @@ const level1List = computed(() =>
deptList.value.filter((i) => i.level === 1).sort(sorter)
);
const filteredLevel1List = computed(() => {
const key = keyword.value.trim().toLowerCase();
if (!key) return level1List.value;
return level1List.value.filter((i) =>
i.deptName.toString().toLowerCase().includes(key)
);
});
const contentList = computed(() => {
const children = deptList.value
.filter(
@ -87,31 +104,20 @@ const contentList = computed(() => {
i.level === 2 && i.parentId && i.parentId === selectedParentId.value
)
.sort(sorter);
if (children.length === 0) {
//
const currentParent = deptList.value.find(
(i) => i._id === selectedParentId.value
);
return currentParent ? [{ ...currentParent, children: [] }] : [];
}
const level3List = deptList.value.filter((i) => i.level === 3);
return children.map((item) => ({
...item,
children: level3List.filter((c) => c.parentId === item._id).sort(sorter),
}));
return children;
});
function isSelected(item) {
const targetId = selectedDeptId.value;
return !!targetId && (item.deptId === targetId || item._id === targetId);
return !!targetId && (item.deptId === targetId || item.deptId === targetId);
}
async function fetchDeptList() {
uni.showLoading({ title: "加载中..." });
try {
const res = await api("getDeptList");
if (res && res.success && Array.isArray(res.data.list)) {
deptList.value = res.data.list;
if (res && res.success && Array.isArray(res.data)) {
deptList.value = res.data;
hydrateSelectedParent();
} else {
toast(res?.message || "获取科室失败");
@ -130,7 +136,7 @@ function hydrateSelectedParent() {
const match =
deptList.value.find(
(i) =>
i._id === selectedDeptId.value || i.deptId === selectedDeptId.value
i.deptId === selectedDeptId.value || i.deptId === selectedDeptId.value
) || null;
if (match?.parentId) {
selectedParentId.value = match.parentId;
@ -144,12 +150,25 @@ function hydrateSelectedParent() {
//
const first = level1List.value[0];
if (first) {
selectedParentId.value = first._id;
selectedParentId.value = first.deptId;
}
}
watch(
filteredLevel1List,
(list) => {
if (!list.length) return;
const exists = list.some((i) => i.deptId === selectedParentId.value);
if (!exists) {
selectedParentId.value = list[0].deptId;
}
},
{ immediate: false }
);
function selectParent(item) {
selectedParentId.value = item._id;
selectedParentId.value = item.deptId;
console.log("selectedParentId", selectedParentId.value);
}
function emitSelection(item) {
@ -158,14 +177,16 @@ function emitSelection(item) {
? getOpenerEventChannel()
: null;
eventChannel?.emit("deptSelected", {
id: item._id,
deptId: item.deptId || item._id,
id: item.deptId,
deptId: item.deptId || item.deptId,
name: item.deptName,
level: item.level,
parentId: item.parentId,
});
}
function selectDept(item) {
selectedDeptId.value = item.deptId || item._id;
selectedDeptId.value = item.deptId || item.deptId;
emitSelection(item);
uni.navigateBack();
}
@ -211,9 +232,43 @@ onLoad((opts) => {
}
.sidebar {
width: 210rpx;
width: 230rpx;
background: #f8f9fb;
border-right: 1px solid #eef0f5;
display: flex;
flex-direction: column;
overflow-y: auto;
}
.sidebar-search {
padding: 16rpx 14rpx 12rpx;
display: flex;
align-items: center;
gap: 10rpx;
}
.search-input {
flex: 1;
height: 64rpx;
padding: 0 20rpx;
border-radius: 32rpx;
background: #fff;
border: 1px solid #e5e8ef;
font-size: 26rpx;
}
.search-placeholder {
color: #a0a8b8;
}
.clear-btn {
font-size: 24rpx;
color: #2a6ff2;
padding: 6rpx 10rpx;
}
.sidebar-list {
flex: 1;
}
.sidebar-item {
@ -237,6 +292,13 @@ onLoad((opts) => {
line-height: 1.4;
}
.sidebar-empty {
padding: 40rpx 16rpx;
font-size: 24rpx;
color: #8c94a6;
text-align: center;
}
.content {
flex: 1;
background: #fff;

View File

@ -3,17 +3,13 @@
<!-- 表单区域 -->
<view class="form-section bg-white">
<!-- 姓名 -->
<common-cell name="姓名" :required="true">
<view class="form-content__wrapper">
<input
class="flex-main-content text-right"
v-model="formData.name"
placeholder="请输入"
placeholder-style="color: #999"
/>
<uni-icons class="form-arrow" type="arrowright"></uni-icons>
</view>
</common-cell>
<form-input
name="姓名"
:required="true"
:form="formData"
title="name"
@change="handleFieldChange"
/>
<!-- 头像 -->
<common-cell name="头像">
<view class="form-content__wrapper" @click="chooseAvatar">
@ -24,9 +20,6 @@
:src="formData.avatar"
mode="aspectFill"
/>
<view v-else class="avatar-placeholder">
<text class="avatar-icon">👤</text>
</view>
</view>
<uni-icons class="form-arrow" type="arrowright"></uni-icons>
</view>
@ -39,14 +32,12 @@
:range="genderOptions"
@change="handleFieldChange"
/>
<!-- 手机号不可修改 -->
<common-cell name="手机号 (不可修改)">
<view class="form-content__wrapper">
<view class="flex-main-content text-dark">{{ formData.phone }}</view>
<view class="flex-main-content text-dark">{{ formData.mobile }}</view>
</view>
</common-cell>
<!-- 岗位 -->
<form-select
name="岗位"
@ -55,7 +46,6 @@
:range="positionOptions"
@change="handleFieldChange"
/>
<!-- 职称 -->
<form-select
name="职称"
@ -64,9 +54,8 @@
:range="titleOptions"
@change="handleFieldChange"
/>
<!-- 科室 -->
<common-cell name="科室" :required="true">
<common-cell name="科室">
<view class="form-content__wrapper" @click="openDepartmentSelect">
<view
class="flex-main-content text-right"
@ -78,6 +67,7 @@
</view>
</common-cell>
<!-- 个人介绍 -->
<form-textarea
name="个人介绍"
@ -87,7 +77,6 @@
@change="handleFieldChange"
/>
</view>
<!-- 底部按钮 -->
<view class="button-footer">
<view class="btn btn-cancel" @click="handleCancel">取消</view>
@ -99,26 +88,22 @@
<script setup>
import { ref } from "vue";
import useGuard from "@/hooks/useGuard.js";
import {
getDoctorInfoByAccountId,
updateDoctorInfo,
} from "@/api/doctor/doctor.js";
import { uploadFile } from "@/api/file.js";
import { chooseAndUploadImage } from "@/utils/file.js";
import useAccountStore from "@/store/account.js";
import { storeToRefs } from "pinia";
import CommonCell from "@/components/form-template/common-cell.vue";
import FormInput from "@/components/form-template/form-cell/form-input.vue";
import FormSelect from "@/components/form-template/form-cell/form-select.vue";
import FormTextarea from "@/components/form-template/form-cell/form-textarea.vue";
const { account, mobile } = storeToRefs(useAccountStore());
import api from "@/utils/api.js";
const { account, doctorInfo } = storeToRefs(useAccountStore());
const { useLoad } = useGuard();
//
const formData = ref({
name: "",
avatar: "",
gender: "",
phone: "",
mobile: "",
position: "",
title: "",
department: "",
@ -130,7 +115,7 @@ const formData = ref({
//
const genderOptions = ["男", "女"];
const positionOptions = ["医生", "护士", "药师", "技师", "其他"];
const titleOptions = ["主任医师", "副主任医师", "主治医师", "住院医师", "其他"];
const titleOptions = ["主任医师", "副主任医师", "主治医师", "医师", "其他"];
//
const handleFieldChange = (e) => {
@ -138,40 +123,17 @@ const handleFieldChange = (e) => {
};
//
const chooseAvatar = () => {
uni.chooseImage({
count: 1,
sizeType: ["compressed"],
sourceType: ["album", "camera"],
success: async (res) => {
const tempFilePath = res.tempFilePaths[0];
uni.showLoading({
title: "上传中...",
});
try {
const uploadRes = await uploadFile(tempFilePath, "other", "public");
if (uploadRes && uploadRes.previewUrl) {
formData.value.avatar = uploadRes.previewUrl;
uni.hideLoading();
uni.showToast({
title: "上传成功",
icon: "success",
});
} else {
throw new Error("上传失败");
}
} catch (error) {
uni.hideLoading();
uni.showToast({
title: "上传失败",
icon: "none",
});
}
},
const chooseAvatar = async () => {
const uploadRes = await chooseAndUploadImage({
businessType: "other",
accessLevel: "public",
loadingTitle: "上传中...",
});
if (uploadRes?.previewUrl) {
formData.value.avatar = uploadRes.previewUrl;
}
};
//
const handleCancel = () => {
uni.navigateBack();
};
@ -186,98 +148,45 @@ const handleSave = async () => {
});
return;
}
uni.showLoading({
title: "保存中...",
});
try {
//
const result = await updateDoctorInfo({
name: formData.value.name,
avatar: formData.value.avatar,
gender: formData.value.gender,
position: formData.value.position,
title: formData.value.title,
departmentId: formData.value.departmentId,
department: formData.value.departmentName || formData.value.department,
intro: formData.value.intro,
});
uni.hideLoading();
if (result && result.success) {
uni.showToast({
title: "保存成功",
icon: "success",
});
setTimeout(() => {
uni.navigateBack();
}, 1500);
} else {
uni.showToast({
title: result?.message || "保存失败",
icon: "none",
});
}
} catch (error) {
uni.hideLoading();
uni.showToast({
title: "保存失败",
icon: "none",
});
console.error("保存失败:", error);
}
};
//
const loadDoctorInfo = async () => {
if (!account.value?.id) {
return;
}
try {
uni.showLoading({
title: "加载中...",
});
const result = await getDoctorInfoByAccountId(account.value.id);
uni.hideLoading();
if (result && result.success && result.data) {
const doctorInfo = result.data;
formData.value = {
name: doctorInfo.name || "",
avatar: doctorInfo.avatar || "",
gender: doctorInfo.gender || "",
phone: doctorInfo.phone || mobile.value || "",
position: doctorInfo.position || "",
title: doctorInfo.title || "",
department: doctorInfo.department || "",
departmentName: doctorInfo.department || "",
departmentId: doctorInfo.departmentId || "",
intro: doctorInfo.intro || "",
};
} else {
//
if (mobile.value) {
formData.value.phone = mobile.value;
}
}
} catch (error) {
uni.hideLoading();
console.error("加载医生信息失败:", error);
}
};
useLoad(() => {
//
if (mobile.value && !formData.value.phone) {
formData.value.phone = mobile.value;
debugger
if (doctorInfo.value) {
formData.value = doctorInfo.value;
} else {
formData.value.mobile = account.value.mobile;
}
loadDoctorInfo();
});
//
const createDoctorInfo = async () => {
let params = {
anotherName: formData.value.name,
avatar: formData.value.avatar,
gender: formData.value.gender,
mobile: formData.value.mobile,
deptIds: [],
};
const res = await api("addCorpMember", {
params,
});
if (res.success && res.data) {
uni.showToast({
title: "创建成功",
icon: "success",
});
} else {
uni.showToast({
title: "创建失败",
icon: "none",
});
console.error("创建医生信息失败:", res);
}
};
//
const openDepartmentSelect = () => {
uni.navigateTo({

View File

@ -1,20 +1,20 @@
export default [
{
path: 'pages/message/message',
meta: { title: '首页', login: true },
meta: { title: '首页', login: false },
style: { navigationStyle: 'custom' }
},
{
path: 'pages/work/work',
meta: { title: '工作台', login: true }
meta: { title: '工作台', login: false }
},
{
path: 'pages/work/profile',
meta: { title: '完善个人信息', login: true }
meta: { title: '完善个人信息', login: false }
},
{
path: 'pages/work/department-select',
meta: { title: '选择科室', login: true }
meta: { title: '选择科室', login: false }
}
]

View File

@ -12,14 +12,14 @@ export default defineStore("accountStore", () => {
const loading = ref(false)
// IM 相关
const openid = ref("");
const isIMInitialized = ref(false);
// 手机号(从授权登录获取)
const mobile = ref(uni.getStorageSync('user_mobile') || '');
// 医生信息
const doctorInfo = ref(null);
async function login(phoneCode = '') {
debugger
if (loading.value) return;
loading.value = true;
try {
const { code } = await uni.login({
appid,
@ -32,18 +32,23 @@ export default defineStore("accountStore", () => {
phoneCode,
code,
});
loading.value = false
console.log(res)
if (res.success && res.data && res.data.mobile) {
account.value = res.data;
openid.value = res.data.openid || res.data.openId || res.data.userId || "";
isIMInitialized.value = false;
clearInitIMPromise();
// 存储手机号
if (res.data.mobile) {
mobile.value = res.data.mobile;
uni.setStorageSync('user_mobile', res.data.mobile);
loading.value = false;
if (res.success && res.data) {
if (!res.data.mobile) {
const pages = getCurrentPages();
const current = pages[pages.length - 1];
const params = current && current.options
? Object.keys(current.options).map(key => `${key}=${current.options[key]}`).join('&')
: '';
const redirectUrl = current && current.route ? `/${current.route}${params ? `?${params}` : ''}` : '';
const target = redirectUrl ? `/pages/login/login?redirect=${encodeURIComponent(redirectUrl)}` : '/pages/login/login';
uni.redirectTo({ url: target });
return;
}
account.value = res.data;
openid.value = res.data.openid;
debugger;
await getDoctorInfo(openid.value);
return res.data
}
}
@ -54,25 +59,18 @@ export default defineStore("accountStore", () => {
loading.value = false
}
/**
* 登录后初始化 IM供聊天页调用
* @param {string} userID - IM userID通常用 openid/openId
*/
async function initIMAfterLogin(userID) {
const uid = userID || openid.value;
if (!uid) {
toast("缺少 openid无法初始化IM");
return false;
}
async function getDoctorInfo(weChatOpenId) {
try {
await getInitIMPromise(uid, true);
isIMInitialized.value = true;
return true;
const res = await api('getCorpMemberData', {
weChatOpenId,
});
if (res.success && res.data) {
doctorInfo.value = res.data;
}
} catch (e) {
isIMInitialized.value = false;
return false;
console.error('获取医生信息失败:', e);
}
}
return { account, openid, isIMInitialized, mobile, login, initIMAfterLogin }
return { account, openid, doctorInfo, login }
})

View File

@ -7,7 +7,10 @@ const urlsConfig = {
getTeamData: 'getTeamData',
queryWxJoinedTeams: 'queryWxJoinedTeams',
wxAppLogin: 'wxAppLogin',
getDeptList:'getHlwDeptList',
getDeptList: 'getRealDeptList',
getHospitalList: 'getRealHospital',
addCorpMember: 'addCorpMember',
getCorpMemberData: 'getCorpMemberData'
},
knowledgeBase: {
@ -25,6 +28,7 @@ const urlsConfig = {
wecom: {
addContactWay: 'addContactWay'
}
}
const urls = Object.keys(urlsConfig).reduce((acc, path) => {
const config = urlsConfig[path] || {};
@ -54,4 +58,5 @@ export default async function api(urlId, data) {
type,
}
})
}
}

75
utils/file.js Normal file
View File

@ -0,0 +1,75 @@
const env = __VITE_ENV__;
export async function uploadFile(tempFilePath, businessType, accessLevel = 'public') {
try {
const res = await new Promise((resolve, reject) => {
uni.uploadFile({
url: `${env.MP_API_BASE_URL}/upload`,
filePath: tempFilePath,
name: 'file',
formData: { businessType, accessLevel },
success: (resp) => resolve(resp),
fail: (err) => reject(err),
});
});
const data = typeof res.data === 'string' ? JSON.parse(res.data) : res.data;
if (data && data.success) {
return data.data;
}
} catch (e) {
console.log('upload file error:', e);
}
return undefined;
}
/**
* 选择单张图片并上传成功返回上传结果接口返回的 data.data
* - 内部会处理 loading / toast
* - 失败或取消返回 null
*/
export async function chooseAndUploadImage(options = {}) {
const {
count = 1,
sizeType = ['compressed'],
sourceType = ['album', 'camera'],
businessType = 'other',
accessLevel = 'public',
loadingTitle = '上传中...',
successToast = '上传成功',
failToast = '上传失败',
} = options;
const imageResult = await new Promise((resolve) => {
uni.chooseImage({
count,
sizeType,
sourceType,
success: (res) => resolve(res),
fail: () => resolve(null),
});
});
const tempFilePath = imageResult?.tempFilePaths?.[0];
if (!tempFilePath) {
return null;
}
uni.showLoading({ title: loadingTitle });
try {
const uploadRes = await uploadFile(tempFilePath, businessType, accessLevel);
uni.hideLoading();
if (uploadRes) {
uni.showToast({ title: successToast, icon: 'success' });
return uploadRes;
}
uni.showToast({ title: failToast, icon: 'none' });
return null;
} catch (e) {
uni.hideLoading();
uni.showToast({ title: failToast, icon: 'none' });
return null;
}
}