Merge remote-tracking branch 'origin/dev-wdb' into dev-hjf
This commit is contained in:
commit
7bc3e9e4c8
@ -1,28 +1,28 @@
|
||||
{
|
||||
"name" : "ykt-wxapp",
|
||||
"appid" : "__UNI__06F5B0E",
|
||||
"description" : "",
|
||||
"versionName" : "1.0.0",
|
||||
"versionCode" : "100",
|
||||
"transformPx" : false,
|
||||
"name": "ykt-team-wxapp",
|
||||
"appid": "__UNI__3EBDA15",
|
||||
"description": "",
|
||||
"versionName": "1.0.0",
|
||||
"versionCode": "100",
|
||||
"transformPx": false,
|
||||
/* 5+App特有相关 */
|
||||
"app-plus" : {
|
||||
"usingComponents" : true,
|
||||
"nvueStyleCompiler" : "uni-app",
|
||||
"compilerVersion" : 3,
|
||||
"splashscreen" : {
|
||||
"alwaysShowBeforeRender" : true,
|
||||
"waiting" : true,
|
||||
"autoclose" : true,
|
||||
"delay" : 0
|
||||
"app-plus": {
|
||||
"usingComponents": true,
|
||||
"nvueStyleCompiler": "uni-app",
|
||||
"compilerVersion": 3,
|
||||
"splashscreen": {
|
||||
"alwaysShowBeforeRender": true,
|
||||
"waiting": true,
|
||||
"autoclose": true,
|
||||
"delay": 0
|
||||
},
|
||||
/* 模块配置 */
|
||||
"modules" : {},
|
||||
"modules": {},
|
||||
/* 应用发布信息 */
|
||||
"distribute" : {
|
||||
"distribute": {
|
||||
/* android打包配置 */
|
||||
"android" : {
|
||||
"permissions" : [
|
||||
"android": {
|
||||
"permissions": [
|
||||
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
|
||||
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
|
||||
@ -41,32 +41,32 @@
|
||||
]
|
||||
},
|
||||
/* ios打包配置 */
|
||||
"ios" : {},
|
||||
"ios": {},
|
||||
/* SDK配置 */
|
||||
"sdkConfigs" : {}
|
||||
"sdkConfigs": {}
|
||||
}
|
||||
},
|
||||
/* 快应用特有相关 */
|
||||
"quickapp" : {},
|
||||
"quickapp": {},
|
||||
/* 小程序特有相关 */
|
||||
"mp-weixin" : {
|
||||
"appid" : "wx93af55767423938e",
|
||||
"setting" : {
|
||||
"urlCheck" : false
|
||||
"mp-weixin": {
|
||||
"appid": "wx93af55767423938e",
|
||||
"setting": {
|
||||
"urlCheck": false
|
||||
},
|
||||
"usingComponents" : true
|
||||
"usingComponents": true
|
||||
},
|
||||
"mp-alipay" : {
|
||||
"usingComponents" : true
|
||||
"mp-alipay": {
|
||||
"usingComponents": true
|
||||
},
|
||||
"mp-baidu" : {
|
||||
"usingComponents" : true
|
||||
"mp-baidu": {
|
||||
"usingComponents": true
|
||||
},
|
||||
"mp-toutiao" : {
|
||||
"usingComponents" : true
|
||||
"mp-toutiao": {
|
||||
"usingComponents": true
|
||||
},
|
||||
"uniStatistics" : {
|
||||
"enable" : false
|
||||
"uniStatistics": {
|
||||
"enable": false
|
||||
},
|
||||
"vueVersion" : "3"
|
||||
}
|
||||
"vueVersion": "3"
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "ykt-wxapp",
|
||||
"name": "医客通患者端",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "main.js",
|
||||
|
||||
1
pages/home/avatar.svg
Normal file
1
pages/home/avatar.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 5.4 KiB |
@ -16,6 +16,101 @@ $primary-color: #0877F1;
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
|
||||
/* 患者信息栏样式 */
|
||||
.patient-info-bar {
|
||||
position: relative;
|
||||
background: #fff;
|
||||
border-bottom: 1rpx solid #f0f0f0;
|
||||
padding: 20rpx 32rpx;
|
||||
z-index: 10;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.patient-info-content {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.patient-basic-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16rpx;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.patient-name {
|
||||
font-size: 32rpx;
|
||||
color: #333;
|
||||
font-weight: 600;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
max-width: 200rpx;
|
||||
}
|
||||
|
||||
.patient-detail {
|
||||
font-size: 28rpx;
|
||||
color: #999;
|
||||
white-space: nowrap;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.status-badge {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4rpx;
|
||||
padding: 8rpx 16rpx;
|
||||
border-radius: 20rpx;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.badge-text {
|
||||
font-size: 24rpx;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.badge-pending {
|
||||
background: #fff3cd;
|
||||
|
||||
.badge-text {
|
||||
color: #856404;
|
||||
}
|
||||
}
|
||||
|
||||
.badge-processing {
|
||||
background: #d1ecf1;
|
||||
|
||||
.badge-text {
|
||||
color: #0c5460;
|
||||
}
|
||||
}
|
||||
|
||||
.badge-finished {
|
||||
background: #d4edda;
|
||||
|
||||
.badge-text {
|
||||
color: #155724;
|
||||
}
|
||||
}
|
||||
|
||||
.badge-cancelled {
|
||||
background: #f8d7da;
|
||||
|
||||
.badge-text {
|
||||
color: #721c24;
|
||||
}
|
||||
}
|
||||
|
||||
.badge-rejected {
|
||||
background: #f8d7da;
|
||||
|
||||
.badge-text {
|
||||
color: #721c24;
|
||||
}
|
||||
}
|
||||
|
||||
.chat-content {
|
||||
flex: 1;
|
||||
box-sizing: border-box;
|
||||
@ -348,7 +443,7 @@ $primary-color: #0877F1;
|
||||
.text-input,
|
||||
.voice-input-btn {
|
||||
flex: 1;
|
||||
padding: 16rpx 46rpx;
|
||||
padding: 26rpx 46rpx;
|
||||
background-color: #f3f5fa;
|
||||
border-radius: 20rpx;
|
||||
margin: 0 16rpx;
|
||||
@ -931,7 +1026,7 @@ $primary-color: #0877F1;
|
||||
.text-input::-moz-placeholder,
|
||||
.text-input:-ms-input-placeholder,
|
||||
.text-input::placeholder {
|
||||
line-height: normal;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.voice-input-btn::-webkit-input-placeholder,
|
||||
|
||||
@ -1,13 +1,18 @@
|
||||
import { ref, computed } from 'vue'
|
||||
import { onShow, onUnload } from '@dcloudio/uni-app'
|
||||
import api from '@/utils/api.js'
|
||||
import useTeamStore from '@/store/team.js'
|
||||
|
||||
/**
|
||||
* 简单的群聊hook
|
||||
* 群聊hook - 管理群聊成员和头像
|
||||
* @param {string} groupID 群组ID
|
||||
*/
|
||||
export default function useGroupChat(groupID) {
|
||||
const groupInfo = ref({})
|
||||
const members = ref([])
|
||||
const teamMemberIds = ref([]) // 存储团队成员的userId列表
|
||||
const patientId = ref('') // 存储患者ID
|
||||
const teamStore = useTeamStore()
|
||||
|
||||
// 群聊成员映射
|
||||
const chatMember = computed(() => {
|
||||
@ -15,30 +20,92 @@ export default function useGroupChat(groupID) {
|
||||
members.value.forEach(member => {
|
||||
res[member.id] = {
|
||||
name: member.name,
|
||||
avatar: member.avatar || '/static/default-avatar.png'
|
||||
avatar: member.avatar,
|
||||
isTeamMember: member.isTeamMember // 标记是否为团队成员
|
||||
}
|
||||
// 如果成员有 miniAppId(患者的聊天 userID),也添加一个映射(用于消息的 from 字段)
|
||||
if (member.miniAppId) {
|
||||
res[member.miniAppId] = {
|
||||
name: member.name,
|
||||
avatar: member.avatar,
|
||||
isTeamMember: member.isTeamMember
|
||||
}
|
||||
}
|
||||
})
|
||||
return res
|
||||
})
|
||||
|
||||
// 获取群聊信息
|
||||
// 判断某个userId是否为团队成员
|
||||
const isTeamMember = (userId) => {
|
||||
return teamMemberIds.value.includes(userId)
|
||||
}
|
||||
|
||||
// 获取用户头像(根据是否为团队成员返回不同的默认头像)
|
||||
const getUserAvatar = (userId) => {
|
||||
const member = chatMember.value[userId]
|
||||
if (!member) {
|
||||
// 如果找不到成员信息,根据是否为团队成员返回默认头像
|
||||
// 团队成员和患者都使用 default-avatar.png
|
||||
return '/static/default-avatar.png'
|
||||
}
|
||||
|
||||
// 如果有头像且不为空字符串,返回头像
|
||||
if (member.avatar && member.avatar.trim() !== '') {
|
||||
return member.avatar
|
||||
}
|
||||
|
||||
// 否则使用默认头像
|
||||
return '/static/default-avatar.png'
|
||||
}
|
||||
|
||||
// 获取群聊信息和成员头像
|
||||
async function getGroupInfo() {
|
||||
const gid = typeof groupID === 'string' ? groupID : groupID.value
|
||||
if (!gid) return
|
||||
|
||||
try {
|
||||
// 这里可以调用API获取群聊信息
|
||||
// const res = await getGroupDetail(gid)
|
||||
// if (res && res.success) {
|
||||
// groupInfo.value = res.data
|
||||
// members.value = res.data.members || []
|
||||
// }
|
||||
// 1. 获取群聊基本信息
|
||||
const groupResult = await api('getGroupListByGroupId', { groupId: gid })
|
||||
|
||||
// 暂时使用本地数据
|
||||
groupInfo.value = {
|
||||
groupID: gid,
|
||||
name: '群聊',
|
||||
status: 'active'
|
||||
if (groupResult && groupResult.success && groupResult.data) {
|
||||
groupInfo.value = {
|
||||
groupID: gid,
|
||||
name: groupResult.data.team?.name || '群聊',
|
||||
status: groupResult.data.orderStatus || 'active',
|
||||
teamId: groupResult.data.teamId
|
||||
}
|
||||
|
||||
// 2. 如果有teamId,获取团队成员头像和名称
|
||||
if (groupResult.data.teamId) {
|
||||
const memberMap = await teamStore.getTeamMemberAvatarsAndName(groupResult.data.teamId)
|
||||
|
||||
// 3. 存储团队成员ID列表
|
||||
teamMemberIds.value = Object.keys(memberMap)
|
||||
|
||||
// 4. 构建团队成员列表(从返回的 { userId: { avatar, name } } 中提取)
|
||||
members.value = teamMemberIds.value.map(userId => {
|
||||
const memberInfo = memberMap[userId] || {}
|
||||
return {
|
||||
id: userId,
|
||||
name: memberInfo.name || userId, // 使用返回的 name,如果没有则用 userId
|
||||
avatar: memberInfo.avatar || '', // 使用返回的 avatar
|
||||
isTeamMember: true
|
||||
}
|
||||
})
|
||||
|
||||
// 5. 添加患者信息(使用默认患者头像)
|
||||
if (groupResult.data.patient) {
|
||||
const pid = groupResult.data.patientId?.toString() || ''
|
||||
patientId.value = pid
|
||||
members.value.push({
|
||||
id: pid,
|
||||
name: groupResult.data.patient.name || '患者',
|
||||
avatar: '', // 患者不设置头像,使用默认
|
||||
isTeamMember: false,
|
||||
miniAppId: groupResult.data.patient.miniAppId || '' // 患者的聊天 userID
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取群聊信息失败:', error)
|
||||
@ -57,6 +124,8 @@ export default function useGroupChat(groupID) {
|
||||
groupInfo,
|
||||
members,
|
||||
chatMember,
|
||||
getGroupInfo
|
||||
getGroupInfo,
|
||||
isTeamMember,
|
||||
getUserAvatar
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,20 @@
|
||||
<template>
|
||||
<view class="chat-page">
|
||||
<!-- 患者信息栏 -->
|
||||
<view class="patient-info-bar" v-if="patientInfo.name">
|
||||
<view class="patient-info-content">
|
||||
<view class="patient-basic-info">
|
||||
<text class="patient-name">{{ patientInfo.name }}</text>
|
||||
<text class="patient-detail"
|
||||
>{{ patientInfo.sex }} · {{ patientInfo.age }}岁</text
|
||||
>
|
||||
</view>
|
||||
<view class="status-badge" :class="chatStatusInfo.badgeClass" v-if="chatStatusInfo.badgeText">
|
||||
<text class="badge-text">{{ chatStatusInfo.badgeText }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 聊天消息区域 -->
|
||||
<scroll-view
|
||||
class="chat-content"
|
||||
@ -50,23 +65,19 @@
|
||||
|
||||
<!-- 消息内容 -->
|
||||
<view v-else class="message-content">
|
||||
<!-- 医生头像(左侧) -->
|
||||
<!-- 发送者头像(统一处理) -->
|
||||
<image
|
||||
v-if="message.flow === 'in'"
|
||||
class="doctor-msg-avatar"
|
||||
:src="
|
||||
chatMember[message.from]?.avatar || '/static/default-avatar.png'
|
||||
"
|
||||
:src="getUserAvatar(message.from)"
|
||||
mode="aspectFill"
|
||||
/>
|
||||
|
||||
<!-- 患者头像(右侧) -->
|
||||
<!-- 发送者头像(统一处理) -->
|
||||
<image
|
||||
v-if="message.flow === 'out'"
|
||||
class="user-msg-avatar"
|
||||
:src="
|
||||
chatMember[message.from]?.avatar || '/static/home/avatar.svg'
|
||||
"
|
||||
:src="getUserAvatar(message.from)"
|
||||
mode="aspectFill"
|
||||
/>
|
||||
|
||||
@ -180,12 +191,12 @@ const { initIMAfterLogin } = useAccountStore();
|
||||
const chatInputRef = ref(null);
|
||||
|
||||
const groupId = ref("");
|
||||
const { chatMember, getGroupInfo } = useGroupChat(groupId);
|
||||
const { chatMember, getGroupInfo, getUserAvatar } = useGroupChat(groupId);
|
||||
|
||||
// 动态设置导航栏标题
|
||||
const updateNavigationTitle = () => {
|
||||
const updateNavigationTitle = (title = "群聊") => {
|
||||
uni.setNavigationBarTitle({
|
||||
title: "群聊",
|
||||
title: title,
|
||||
});
|
||||
};
|
||||
|
||||
@ -202,6 +213,26 @@ const isEvaluationPopupOpen = ref(false);
|
||||
// 订单状态
|
||||
const orderStatus = ref("");
|
||||
|
||||
// 患者信息
|
||||
const patientInfo = ref({
|
||||
name: "",
|
||||
sex: "",
|
||||
age: "",
|
||||
mobile: "",
|
||||
});
|
||||
|
||||
// 患者ID
|
||||
const patientId = ref("");
|
||||
|
||||
// 聊天状态信息
|
||||
const chatStatusInfo = ref({
|
||||
show: false,
|
||||
title: "",
|
||||
detail: "",
|
||||
badgeText: "",
|
||||
badgeClass: "",
|
||||
});
|
||||
|
||||
// 计算弹框显示状态
|
||||
const showConsultCancel = computed(() => orderStatus.value === "pending");
|
||||
const showConsultApply = computed(
|
||||
@ -258,9 +289,33 @@ const fetchGroupOrderStatus = async () => {
|
||||
if (result.success && result.data) {
|
||||
orderStatus.value = result.data.orderStatus || "";
|
||||
corpId.value = result.data.corpId || "";
|
||||
|
||||
// 更新导航栏标题为团队名称
|
||||
const teamName = result.data.team?.name || "群聊";
|
||||
updateNavigationTitle(teamName);
|
||||
|
||||
// 更新患者信息
|
||||
if (result.data.patient) {
|
||||
patientInfo.value = {
|
||||
name: result.data.patient.name || "",
|
||||
sex: result.data.patient.sex || "",
|
||||
age: result.data.patient.age || "",
|
||||
mobile: result.data.patient.mobile || "",
|
||||
};
|
||||
}
|
||||
// 更新患者ID
|
||||
if (result.data.patientId) {
|
||||
patientId.value = result.data.patientId.toString();
|
||||
}
|
||||
|
||||
// 更新聊天状态栏信息
|
||||
updateChatStatusInfo(result.data);
|
||||
|
||||
console.log("获取群组订单状态:", {
|
||||
orderStatus: orderStatus.value,
|
||||
corpId: corpId.value,
|
||||
teamName: teamName,
|
||||
patientInfo: patientInfo.value,
|
||||
});
|
||||
} else {
|
||||
console.error("获取群组订单状态失败:", result.message);
|
||||
@ -270,7 +325,72 @@ const fetchGroupOrderStatus = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
// 处理接收到的系统消息
|
||||
// 更新聊天状态栏信息
|
||||
const updateChatStatusInfo = (groupData) => {
|
||||
const status = groupData.orderStatus || "";
|
||||
|
||||
let statusConfig = {
|
||||
show: false,
|
||||
title: "",
|
||||
detail: "",
|
||||
badgeText: "",
|
||||
badgeClass: "",
|
||||
};
|
||||
|
||||
switch (status) {
|
||||
case "pending":
|
||||
statusConfig = {
|
||||
show: true,
|
||||
title: "等待医生接受",
|
||||
detail: "您的咨询申请已提交",
|
||||
badgeText: "待处理",
|
||||
badgeClass: "badge-pending",
|
||||
};
|
||||
break;
|
||||
case "processing":
|
||||
statusConfig = {
|
||||
show: true,
|
||||
title: "咨询进行中",
|
||||
detail: "医生正在为您服务",
|
||||
badgeText: "进行中",
|
||||
badgeClass: "badge-processing",
|
||||
};
|
||||
break;
|
||||
case "finished":
|
||||
statusConfig = {
|
||||
show: true,
|
||||
title: "咨询已完成",
|
||||
detail: "感谢您的咨询",
|
||||
badgeText: "已完成",
|
||||
badgeClass: "badge-finished",
|
||||
};
|
||||
break;
|
||||
case "cancelled":
|
||||
statusConfig = {
|
||||
show: true,
|
||||
title: "咨询已取消",
|
||||
detail: "您已取消此次咨询",
|
||||
badgeText: "已取消",
|
||||
badgeClass: "badge-cancelled",
|
||||
};
|
||||
break;
|
||||
case "rejected":
|
||||
statusConfig = {
|
||||
show: true,
|
||||
title: "咨询已拒绝",
|
||||
detail: "医生已拒绝您的咨询申请",
|
||||
badgeText: "已拒绝",
|
||||
badgeClass: "badge-rejected",
|
||||
};
|
||||
break;
|
||||
default:
|
||||
statusConfig.show = false;
|
||||
}
|
||||
|
||||
chatStatusInfo.value = statusConfig;
|
||||
};
|
||||
|
||||
// 处理系统消息接收
|
||||
function handleSystemMessageReceived(message) {
|
||||
try {
|
||||
if (!message.payload?.data) return;
|
||||
@ -696,7 +816,7 @@ const handleScrollToUpper = async () => {
|
||||
onShow(() => {
|
||||
if (!account.value || !openid.value) {
|
||||
uni.redirectTo({
|
||||
url: "/pages-center/login/login",
|
||||
url: "/pages/login/login",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
55
store/team.js
Normal file
55
store/team.js
Normal file
@ -0,0 +1,55 @@
|
||||
import { computed, ref } from "vue";
|
||||
import { defineStore, storeToRefs } from "pinia";
|
||||
import api from '@/utils/api';
|
||||
import { toast } from '@/utils/widget';
|
||||
import useAccountStore from "./account";
|
||||
|
||||
|
||||
export default defineStore("teamStore", () => {
|
||||
const { account, doctorInfo } = storeToRefs(useAccountStore());
|
||||
const teams = ref([]);
|
||||
|
||||
const chargeTeams = computed(() => {
|
||||
const userid = doctorInfo.value?.userid;
|
||||
return teams.value.filter(team => {
|
||||
const memberLeaderList = Array.isArray(team.memberLeaderList) ? team.memberLeaderList : [];
|
||||
return memberLeaderList.includes(userid);
|
||||
});
|
||||
})
|
||||
|
||||
async function getTeam(teamId) {
|
||||
if (!teamId || !account.value?.corpId) return;
|
||||
const res = await api('getTeamData', { teamId, corpId: account.value.corpId });
|
||||
if (res && res.data) {
|
||||
return res.data;
|
||||
} else {
|
||||
toast(res?.message || '获取团队信息失败')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
async function getTeams() {
|
||||
const corpId = account.value?.corpId;
|
||||
const mateId = doctorInfo.value?.userid;
|
||||
if (!corpId || !mateId) return;
|
||||
const res = await api('getJoinedTeams', { corpId, mateId });
|
||||
teams.value = res && Array.isArray(res.data) ? res.data : [];
|
||||
}
|
||||
|
||||
// 获取团队成员头像和名称映射
|
||||
async function getTeamMemberAvatarsAndName(teamId) {
|
||||
if (!teamId || !account.value?.corpId) return {};
|
||||
const res = await api('getTeamMemberAvatarsAndName', {
|
||||
teamId,
|
||||
corpId: account.value.corpId
|
||||
});
|
||||
if (res && res.success && res.data) {
|
||||
return res.data;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
return { teams, chargeTeams, getTeam, getTeams, getTeamMemberAvatarsAndName }
|
||||
})
|
||||
@ -9,7 +9,8 @@ const urlsConfig = {
|
||||
wxAppLogin: 'wxAppLogin',
|
||||
getTeamHealthTemplate: 'getTeamHealthTemplate',
|
||||
getTeamHealthTemps: "getTeamHealthTemps",
|
||||
getCorpMemberJob: "getCorpMemberJob"
|
||||
getCorpMemberJob: "getCorpMemberJob",
|
||||
getTeamMemberAvatarsAndName: "getTeamMemberAvatarsAndName"
|
||||
},
|
||||
|
||||
knowledgeBase: {
|
||||
|
||||
@ -926,7 +926,7 @@ class TimChatManager {
|
||||
uni.removeStorageSync('account')
|
||||
uni.removeStorageSync('openid')
|
||||
uni.reLaunch({
|
||||
url: '/pages-center/login/login'
|
||||
url: '/pages/login/login'
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
@ -50,4 +50,89 @@ export async function confirm(content, opt = {}) {
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// 保存图片到相册
|
||||
export async function saveImageToPhotosAlbum(filePath) {
|
||||
try {
|
||||
// 检查授权
|
||||
const authRes = await uni.getSetting()
|
||||
if (!authRes[1].authSetting['scope.writePhotosAlbum']) {
|
||||
// 请求授权
|
||||
try {
|
||||
await uni.authorize({ scope: 'scope.writePhotosAlbum' })
|
||||
} catch (err) {
|
||||
// 用户拒绝授权,引导去设置
|
||||
const [modalErr, modalRes] = await uni.showModal({
|
||||
title: '提示',
|
||||
content: '需要您授权保存相册',
|
||||
confirmText: '去设置',
|
||||
cancelText: '取消'
|
||||
})
|
||||
|
||||
if (modalRes && modalRes.confirm) {
|
||||
await uni.openSetting()
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// 保存图片
|
||||
await uni.saveImageToPhotosAlbum({ filePath })
|
||||
await toast('保存成功')
|
||||
} catch (err) {
|
||||
console.error('保存图片失败:', err)
|
||||
await toast('保存失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 分享到微信
|
||||
export function shareToWeChat(options = {}) {
|
||||
const { title = '', path = '', imageUrl = '' } = options
|
||||
|
||||
return {
|
||||
title,
|
||||
path,
|
||||
imageUrl,
|
||||
success: () => {
|
||||
toast('分享成功')
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('分享失败:', err)
|
||||
toast('分享失败')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 分享第三方小程序给微信好友
|
||||
export function shareThirdPartyMiniProgram(options = {}) {
|
||||
const {
|
||||
title = '',
|
||||
appId = '',
|
||||
path = '',
|
||||
imageUrl = '',
|
||||
webUrl = '',
|
||||
miniProgramType = 0
|
||||
} = options
|
||||
|
||||
if (!appId) {
|
||||
console.error('分享第三方小程序需要提供 appId')
|
||||
toast('分享配置错误')
|
||||
return null
|
||||
}
|
||||
|
||||
return {
|
||||
title,
|
||||
path,
|
||||
imageUrl,
|
||||
miniProgramType, // 0-正式版 1-开发版 2-体验版
|
||||
webpageUrl: webUrl, // 兼容低版本的网页链接
|
||||
success: () => {
|
||||
toast('分享成功')
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('分享失败:', err)
|
||||
toast('分享失败')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user