登录页面和文件打开方式
This commit is contained in:
@@ -346,6 +346,7 @@
|
|||||||
chooseFile
|
chooseFile
|
||||||
} from '@/uni_modules/lime-choose-file'
|
} from '@/uni_modules/lime-choose-file'
|
||||||
import socketManager from '../../utils/socket';
|
import socketManager from '../../utils/socket';
|
||||||
|
import { openFile as openFileNative, downloadAndOpen } from '@/utils/fileOpener.js'
|
||||||
|
|
||||||
const friendSocketStore = useFriendSocketStore()
|
const friendSocketStore = useFriendSocketStore()
|
||||||
// 连接实时通讯eriendsocket
|
// 连接实时通讯eriendsocket
|
||||||
@@ -523,15 +524,7 @@
|
|||||||
}
|
}
|
||||||
// 打开文件
|
// 打开文件
|
||||||
const openFile = (url) => {
|
const openFile = (url) => {
|
||||||
uni.downloadFile({
|
downloadAndOpen(url);
|
||||||
url: url,
|
|
||||||
success: (res) => {
|
|
||||||
uni.openDocument({
|
|
||||||
filePath: res.tempFilePath,
|
|
||||||
showMenu: true
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
// 文件大小格式化
|
// 文件大小格式化
|
||||||
const formatFileSize = (size) => {
|
const formatFileSize = (size) => {
|
||||||
@@ -906,12 +899,8 @@
|
|||||||
success: (downloadRes) => {
|
success: (downloadRes) => {
|
||||||
if (downloadRes.statusCode === 200) {
|
if (downloadRes.statusCode === 200) {
|
||||||
hideDownloadToast()
|
hideDownloadToast()
|
||||||
uni.openDocument({
|
openFileNative(downloadRes.tempFilePath, () => {
|
||||||
filePath: downloadRes.tempFilePath,
|
showDownloadToast('error', '无法打开此文件', 2500)
|
||||||
showMenu: true,
|
|
||||||
fail: () => {
|
|
||||||
showDownloadToast('error', '无法打开此文件', 2500)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
showDownloadToast('error', '下载失败', 2500)
|
showDownloadToast('error', '下载失败', 2500)
|
||||||
@@ -1188,14 +1177,16 @@
|
|||||||
if (reason === 'pc offline') {
|
if (reason === 'pc offline') {
|
||||||
isThinking.value = false
|
isThinking.value = false
|
||||||
socketStore.authFailReason = ''
|
socketStore.authFailReason = ''
|
||||||
nextTick(() => {
|
uni.showToast({
|
||||||
uni.showModal({
|
title: 'PC端不在线,请先登录',
|
||||||
title: '提示',
|
icon: 'none',
|
||||||
content: 'PC端不在线,不可聊天',
|
duration: 500
|
||||||
showCancel: false,
|
|
||||||
confirmText: '知道了'
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
setTimeout(() => {
|
||||||
|
uni.reLaunch({
|
||||||
|
url: '/pages/Login/Login'
|
||||||
|
})
|
||||||
|
}, 500)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -475,6 +475,7 @@
|
|||||||
uploadCloudDbFile,
|
uploadCloudDbFile,
|
||||||
deleteCloudDb
|
deleteCloudDb
|
||||||
} from '@/utils/cloud-api.js';
|
} from '@/utils/cloud-api.js';
|
||||||
|
import { openFile as openFileNative } from '@/utils/fileOpener.js'
|
||||||
|
|
||||||
const userToken = ref('');
|
const userToken = ref('');
|
||||||
const userId = ref('');
|
const userId = ref('');
|
||||||
@@ -826,19 +827,10 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 使用系统默认应用打开
|
// 打开文件(弹出应用选择菜单)
|
||||||
const openFile = (filePath) => {
|
const openFile = (filePath) => {
|
||||||
uni.openDocument({
|
openFileNative(filePath, () => {
|
||||||
filePath: filePath,
|
openFileWithMenu(filePath);
|
||||||
success: () => uni.showToast({
|
|
||||||
title: '打开成功',
|
|
||||||
icon: 'success'
|
|
||||||
}),
|
|
||||||
fail: (err) => {
|
|
||||||
console.error('打开文件失败:', err);
|
|
||||||
// 如果默认应用打开失败,尝试弹出选择菜单
|
|
||||||
openFileWithMenu(filePath);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -121,6 +121,7 @@
|
|||||||
workspaceUploadFileByURL,
|
workspaceUploadFileByURL,
|
||||||
updateWorkspaceFileName
|
updateWorkspaceFileName
|
||||||
} from '@/utils/cloud-api.js'
|
} from '@/utils/cloud-api.js'
|
||||||
|
import { openFile as openFileNative } from '@/utils/fileOpener.js'
|
||||||
|
|
||||||
const UserToken = ref('')
|
const UserToken = ref('')
|
||||||
const workspaceId = ref('')
|
const workspaceId = ref('')
|
||||||
@@ -435,40 +436,10 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 使用系统默认应用打开
|
// 打开文件(弹出应用选择菜单)
|
||||||
const openFile = (filePath) => {
|
const openFile = (filePath) => {
|
||||||
uni.openDocument({
|
openFileNative(filePath, () => {
|
||||||
filePath: filePath,
|
uni.showToast({ title: '无法打开此文件', icon: 'error' });
|
||||||
success: () => uni.showToast({
|
|
||||||
title: '打开成功',
|
|
||||||
icon: 'success'
|
|
||||||
}),
|
|
||||||
fail: (err) => {
|
|
||||||
console.error('打开文件失败:', err);
|
|
||||||
uni.showToast({
|
|
||||||
title: '无法打开此文件',
|
|
||||||
icon: 'error'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// 选择其他应用打开
|
|
||||||
const openFileWithMenu = (filePath) => {
|
|
||||||
uni.openDocument({
|
|
||||||
filePath: filePath,
|
|
||||||
showMenu: true,
|
|
||||||
success: () => uni.showToast({
|
|
||||||
title: '打开成功',
|
|
||||||
icon: 'success'
|
|
||||||
}),
|
|
||||||
fail: (err) => {
|
|
||||||
console.error('打开文件失败:', err);
|
|
||||||
uni.showToast({
|
|
||||||
title: '无法打开此文件',
|
|
||||||
icon: 'error'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -325,6 +325,7 @@
|
|||||||
chooseFile
|
chooseFile
|
||||||
} from '@/uni_modules/lime-choose-file'
|
} from '@/uni_modules/lime-choose-file'
|
||||||
import socketManager from '../../utils/socket';
|
import socketManager from '../../utils/socket';
|
||||||
|
import { openFile as openFileNative } from '@/utils/fileOpener.js'
|
||||||
|
|
||||||
const friendSocketStore = useFriendSocketStore()
|
const friendSocketStore = useFriendSocketStore()
|
||||||
// 连接实时通讯eriendsocket
|
// 连接实时通讯eriendsocket
|
||||||
@@ -490,15 +491,7 @@
|
|||||||
}
|
}
|
||||||
// 打开文件
|
// 打开文件
|
||||||
const openFile = (url) => {
|
const openFile = (url) => {
|
||||||
uni.downloadFile({
|
downloadAndOpen(url);
|
||||||
url: url,
|
|
||||||
success: (res) => {
|
|
||||||
uni.openDocument({
|
|
||||||
filePath: res.tempFilePath,
|
|
||||||
showMenu: true
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
// 文件大小格式化
|
// 文件大小格式化
|
||||||
const formatFileSize = (size) => {
|
const formatFileSize = (size) => {
|
||||||
@@ -1131,14 +1124,16 @@
|
|||||||
if (reason === 'pc offline') {
|
if (reason === 'pc offline') {
|
||||||
isThinking.value = false
|
isThinking.value = false
|
||||||
socketStore.authFailReason = ''
|
socketStore.authFailReason = ''
|
||||||
nextTick(() => {
|
uni.showToast({
|
||||||
uni.showModal({
|
title: 'PC端不在线',
|
||||||
title: '提示',
|
icon: 'none',
|
||||||
content: 'PC端不在线,不可聊天',
|
duration: 1500
|
||||||
showCancel: false,
|
|
||||||
confirmText: '知道了'
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
setTimeout(() => {
|
||||||
|
uni.reLaunch({
|
||||||
|
url: '/pages/Login/Login'
|
||||||
|
})
|
||||||
|
}, 1500)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
;(function(){
|
;(function(){
|
||||||
let u=void 0,isReady=false,onReadyCallbacks=[],isServiceReady=false,onServiceReadyCallbacks=[];
|
let u=void 0,isReady=false,onReadyCallbacks=[],isServiceReady=false,onServiceReadyCallbacks=[];
|
||||||
const __uniConfig = {"pages":[],"globalStyle":{"backgroundColor":"#F8F8F8","navigationBar":{"backgroundColor":"#F8F8F8","titleText":"uni-app","type":"default","titleColor":"#000000"},"isNVue":false},"nvue":{"compiler":"uni-app","styleCompiler":"uni-app","flex-direction":"column"},"renderer":"auto","appname":"test1","splashscreen":{"alwaysShowBeforeRender":true,"autoclose":true},"compilerVersion":"5.07","entryPagePath":"pages/Login/Login","entryPageQuery":"","realEntryPagePath":"","networkTimeout":{"request":60000,"connectSocket":60000,"uploadFile":60000,"downloadFile":60000},"locales":{},"darkmode":false,"themeConfig":{}};
|
const __uniConfig = {"pages":[],"globalStyle":{"backgroundColor":"#F8F8F8","navigationBar":{"backgroundColor":"#F8F8F8","titleText":"uni-app","type":"default","titleColor":"#000000"},"isNVue":false},"nvue":{"compiler":"uni-app","styleCompiler":"uni-app","flex-direction":"column"},"renderer":"auto","appname":"宇恒一号","splashscreen":{"alwaysShowBeforeRender":true,"autoclose":true},"compilerVersion":"5.07","entryPagePath":"pages/Login/Login","entryPageQuery":"","realEntryPagePath":"","networkTimeout":{"request":60000,"connectSocket":60000,"uploadFile":60000,"downloadFile":60000},"locales":{},"darkmode":false,"themeConfig":{}};
|
||||||
const __uniRoutes = [{"path":"pages/Login/Login","meta":{"isQuit":true,"isEntry":true,"titleNView":false,"bounce":"none","softinputMode":"adjustResize","navigationBar":{"titleText":"登录页面","style":"custom","type":"default"},"isNVue":false}},{"path":"pages/Chat/Chat","meta":{"titleNView":false,"bounce":"none","softinputMode":"adjustResize","navigationBar":{"titleText":"聊天页面(主页面)","style":"custom","type":"default"},"isNVue":false}},{"path":"pages/WorkSpace/WorkSpace","meta":{"titleNView":false,"bounce":"none","softinputMode":"adjustResize","navigationBar":{"titleText":"工作区文件管理","style":"custom","type":"default"},"isNVue":false}},{"path":"pages/UserProfileModal/UserProfileModal","meta":{"titleNView":false,"bounce":"none","softinputMode":"adjustResize","navigationBar":{"titleText":"","style":"custom","type":"default"},"isNVue":false}},{"path":"pages/ContactPages/ContactPages","meta":{"titleNView":false,"bounce":"none","softinputMode":"adjustResize","navigationBar":{"titleText":"","style":"custom","type":"default"},"isNVue":false}},{"path":"pages/WorkSpace/TemplateSpace/TemplateSpace","meta":{"titleNView":false,"bounce":"none","softinputMode":"adjustResize","navigationBar":{"titleText":"","style":"custom","type":"default"},"isNVue":false}},{"path":"pages/CloudDatabase/CloudDatabase","meta":{"titleNView":false,"bounce":"none","softinputMode":"adjustResize","navigationBar":{"titleText":"云端数据","style":"custom","type":"default"},"isNVue":false}},{"path":"pages/CloudDbDetail/CloudDbDetail","meta":{"titleNView":false,"bounce":"none","softinputMode":"adjustResize","navigationBar":{"titleText":"数据库详情","style":"custom","type":"default"},"isNVue":false}},{"path":"pages/text/text","meta":{"navigationBar":{"titleText":"","type":"default"},"isNVue":false}},{"path":"pages/text/IntuitiveAipptViewer","meta":{"navigationBar":{"titleText":"","type":"default"},"isNVue":false}},{"path":"pages/WYXD/WYXD","meta":{"titleNView":false,"bounce":"none","navigationBar":{"titleText":"","style":"custom","type":"default"},"isNVue":false}}].map(uniRoute=>(uniRoute.meta.route=uniRoute.path,__uniConfig.pages.push(uniRoute.path),uniRoute.path='/'+uniRoute.path,uniRoute));
|
const __uniRoutes = [{"path":"pages/Login/Login","meta":{"isQuit":true,"isEntry":true,"titleNView":false,"bounce":"none","softinputMode":"adjustResize","navigationBar":{"titleText":"登录页面","style":"custom","type":"default"},"isNVue":false}},{"path":"pages/Chat/Chat","meta":{"titleNView":false,"bounce":"none","softinputMode":"adjustResize","navigationBar":{"titleText":"聊天页面(主页面)","style":"custom","type":"default"},"isNVue":false}},{"path":"pages/WorkSpace/WorkSpace","meta":{"titleNView":false,"bounce":"none","softinputMode":"adjustResize","navigationBar":{"titleText":"工作区文件管理","style":"custom","type":"default"},"isNVue":false}},{"path":"pages/UserProfileModal/UserProfileModal","meta":{"titleNView":false,"bounce":"none","softinputMode":"adjustResize","navigationBar":{"titleText":"","style":"custom","type":"default"},"isNVue":false}},{"path":"pages/ContactPages/ContactPages","meta":{"titleNView":false,"bounce":"none","softinputMode":"adjustResize","navigationBar":{"titleText":"","style":"custom","type":"default"},"isNVue":false}},{"path":"pages/WorkSpace/TemplateSpace/TemplateSpace","meta":{"titleNView":false,"bounce":"none","softinputMode":"adjustResize","navigationBar":{"titleText":"","style":"custom","type":"default"},"isNVue":false}},{"path":"pages/CloudDatabase/CloudDatabase","meta":{"titleNView":false,"bounce":"none","softinputMode":"adjustResize","navigationBar":{"titleText":"云端数据","style":"custom","type":"default"},"isNVue":false}},{"path":"pages/CloudDbDetail/CloudDbDetail","meta":{"titleNView":false,"bounce":"none","softinputMode":"adjustResize","navigationBar":{"titleText":"数据库详情","style":"custom","type":"default"},"isNVue":false}},{"path":"pages/text/text","meta":{"navigationBar":{"titleText":"","type":"default"},"isNVue":false}},{"path":"pages/text/IntuitiveAipptViewer","meta":{"navigationBar":{"titleText":"","type":"default"},"isNVue":false}},{"path":"pages/WYXD/WYXD","meta":{"titleNView":false,"bounce":"none","navigationBar":{"titleText":"","style":"custom","type":"default"},"isNVue":false}}].map(uniRoute=>(uniRoute.meta.route=uniRoute.path,__uniConfig.pages.push(uniRoute.path),uniRoute.path='/'+uniRoute.path,uniRoute));
|
||||||
__uniConfig.styles=[];//styles
|
__uniConfig.styles=[];//styles
|
||||||
__uniConfig.onReady=function(callback){if(__uniConfig.ready){callback()}else{onReadyCallbacks.push(callback)}};Object.defineProperty(__uniConfig,"ready",{get:function(){return isReady},set:function(val){isReady=val;if(!isReady){return}const callbacks=onReadyCallbacks.slice(0);onReadyCallbacks.length=0;callbacks.forEach(function(callback){callback()})}});
|
__uniConfig.onReady=function(callback){if(__uniConfig.ready){callback()}else{onReadyCallbacks.push(callback)}};Object.defineProperty(__uniConfig,"ready",{get:function(){return isReady},set:function(val){isReady=val;if(!isReady){return}const callbacks=onReadyCallbacks.slice(0);onReadyCallbacks.length=0;callbacks.forEach(function(callback){callback()})}});
|
||||||
|
|||||||
467
unpackage/dist/dev/app-plus/app-service.js
vendored
467
unpackage/dist/dev/app-plus/app-service.js
vendored
File diff suppressed because it is too large
Load Diff
2
unpackage/dist/dev/app-plus/manifest.json
vendored
2
unpackage/dist/dev/app-plus/manifest.json
vendored
@@ -5,7 +5,7 @@
|
|||||||
"iPad"
|
"iPad"
|
||||||
],
|
],
|
||||||
"id": "__UNI__923FD9E",
|
"id": "__UNI__923FD9E",
|
||||||
"name": "test1",
|
"name": "宇恒一号",
|
||||||
"version": {
|
"version": {
|
||||||
"name": "1.1.1",
|
"name": "1.1.1",
|
||||||
"code": 2
|
"code": 2
|
||||||
|
|||||||
124
utils/fileOpener.js
Normal file
124
utils/fileOpener.js
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
/**
|
||||||
|
* 文件打开工具 - 强制弹出应用选择器
|
||||||
|
*
|
||||||
|
* uni.openDocument 的 showMenu 和 plus.runtime.openFile 在真机上
|
||||||
|
* 都可能直接跳转默认应用。用 Android 原生 Intent.createChooser
|
||||||
|
* 强制弹出"选择应用"对话框。
|
||||||
|
*
|
||||||
|
* Android 7.0+ 会阻止 file:// URI 暴露给其他应用,需要禁用此限制。
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据文件扩展名获取 MIME 类型
|
||||||
|
*/
|
||||||
|
function getMimeType(filePath) {
|
||||||
|
const ext = filePath.substring(filePath.lastIndexOf('.') + 1).toLowerCase()
|
||||||
|
const mimeMap = {
|
||||||
|
'pdf': 'application/pdf',
|
||||||
|
'doc': 'application/msword',
|
||||||
|
'docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||||
|
'xls': 'application/vnd.ms-excel',
|
||||||
|
'xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||||
|
'ppt': 'application/vnd.ms-powerpoint',
|
||||||
|
'pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
||||||
|
'txt': 'text/plain',
|
||||||
|
'html': 'text/html',
|
||||||
|
'htm': 'text/html',
|
||||||
|
'xml': 'text/xml',
|
||||||
|
'json': 'application/json',
|
||||||
|
'csv': 'text/csv',
|
||||||
|
'jpg': 'image/jpeg',
|
||||||
|
'jpeg': 'image/jpeg',
|
||||||
|
'png': 'image/png',
|
||||||
|
'gif': 'image/gif',
|
||||||
|
'bmp': 'image/bmp',
|
||||||
|
'webp': 'image/webp',
|
||||||
|
'mp4': 'video/mp4',
|
||||||
|
'mp3': 'audio/mpeg',
|
||||||
|
'wav': 'audio/wav',
|
||||||
|
'zip': 'application/zip',
|
||||||
|
'rar': 'application/x-rar-compressed',
|
||||||
|
'7z': 'application/x-7z-compressed',
|
||||||
|
'apk': 'application/vnd.android.package-archive'
|
||||||
|
}
|
||||||
|
return mimeMap[ext] || '*/*'
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 打开文件,弹出应用选择器
|
||||||
|
* @param {string} filePath 本地文件路径
|
||||||
|
* @param {Function} onFail 打开失败时的回调
|
||||||
|
*/
|
||||||
|
export function openFile(filePath, onFail) {
|
||||||
|
// #ifdef APP-PLUS
|
||||||
|
try {
|
||||||
|
const main = plus.android.runtimeMainActivity()
|
||||||
|
const Intent = plus.android.importClass('android.content.Intent')
|
||||||
|
const Uri = plus.android.importClass('android.net.Uri')
|
||||||
|
const File = plus.android.importClass('java.io.File')
|
||||||
|
|
||||||
|
// Android 7.0+ 默认禁止 file:// URI,禁用此限制
|
||||||
|
if (plus.os.sdkInt >= 24) {
|
||||||
|
const StrictMode = plus.android.importClass('android.os.StrictMode')
|
||||||
|
StrictMode.disableDeathOnFileUriExposure()
|
||||||
|
}
|
||||||
|
|
||||||
|
const file = new File(filePath)
|
||||||
|
if (!file.exists()) {
|
||||||
|
throw new Error('文件不存在: ' + filePath)
|
||||||
|
}
|
||||||
|
|
||||||
|
const uri = Uri.fromFile(file)
|
||||||
|
const mimeType = getMimeType(filePath)
|
||||||
|
|
||||||
|
const intent = new Intent(Intent.ACTION_VIEW)
|
||||||
|
intent.setDataAndType(uri, mimeType)
|
||||||
|
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
|
|
||||||
|
// 核心:createChooser 每次必弹选择器,无视已设置的默认应用
|
||||||
|
const chooser = Intent.createChooser(intent, '选择应用打开')
|
||||||
|
main.startActivity(chooser)
|
||||||
|
|
||||||
|
console.log('openFile success - chooser shown')
|
||||||
|
} catch (e) {
|
||||||
|
console.error('openFile native failed, fallback:', e)
|
||||||
|
uni.openDocument({
|
||||||
|
filePath: filePath,
|
||||||
|
showMenu: true,
|
||||||
|
fail: typeof onFail === 'function' ? onFail : () => {}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
// #ifndef APP-PLUS
|
||||||
|
uni.openDocument({
|
||||||
|
filePath: filePath,
|
||||||
|
showMenu: true,
|
||||||
|
fail: typeof onFail === 'function' ? onFail : () => {}
|
||||||
|
})
|
||||||
|
// #endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载文件并打开(弹出应用选择器)
|
||||||
|
* @param {string} url 远程文件 URL
|
||||||
|
* @param {Function} onFail 失败回调
|
||||||
|
*/
|
||||||
|
export function downloadAndOpen(url, onFail) {
|
||||||
|
uni.downloadFile({
|
||||||
|
url: url,
|
||||||
|
success: (res) => {
|
||||||
|
if (res.statusCode === 200) {
|
||||||
|
openFile(res.tempFilePath, onFail)
|
||||||
|
} else {
|
||||||
|
console.error('下载失败, statusCode:', res.statusCode)
|
||||||
|
if (typeof onFail === 'function') onFail()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fail: (err) => {
|
||||||
|
console.error('downloadFile fail:', err)
|
||||||
|
if (typeof onFail === 'function') onFail()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user