文件消息,地理位置消息
This commit is contained in:
@@ -1,183 +1,188 @@
|
|||||||
<template xlang="wxml" minapp="mpvue">
|
<template xlang="wxml" minapp="mpvue">
|
||||||
<view>
|
<view>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
name: 'tki-file-manager',
|
name: 'tki-file-manager',
|
||||||
props: {},
|
props: {},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {}
|
||||||
}
|
},
|
||||||
},
|
methods: {
|
||||||
methods: {
|
_openFile() {
|
||||||
_openFile() {
|
// #ifdef APP-PLUS
|
||||||
// #ifdef APP-PLUS
|
if (plus.os.name.toLowerCase() != "android") {
|
||||||
if (plus.os.name.toLowerCase() != "android") {
|
uni.showModal({
|
||||||
uni.showModal({
|
title: '提示',
|
||||||
title: '提示',
|
content: '仅支持Android平台',
|
||||||
content: '仅支持Android平台',
|
success: function(res) {}
|
||||||
success: function (res) {}
|
});
|
||||||
});
|
return false
|
||||||
return false
|
}
|
||||||
}
|
let that = this
|
||||||
let that = this
|
// java 代码来自 http://www.cnblogs.com/panhouye/archive/2017/04/23/6751710.html
|
||||||
// java 代码来自 http://www.cnblogs.com/panhouye/archive/2017/04/23/6751710.html
|
let main = plus.android.runtimeMainActivity();
|
||||||
let main = plus.android.runtimeMainActivity();
|
let Intent = plus.android.importClass("android.content.Intent");
|
||||||
let Intent = plus.android.importClass("android.content.Intent");
|
|
||||||
|
|
||||||
//
|
//
|
||||||
let fileIntent = new Intent(Intent.ACTION_GET_CONTENT)
|
let fileIntent = new Intent(Intent.ACTION_GET_CONTENT)
|
||||||
//fileIntent.setType(“image/*”);//选择图片
|
//fileIntent.setType(“image/*”);//选择图片
|
||||||
//fileIntent.setType(“audio/*”); //选择音频
|
//fileIntent.setType(“audio/*”); //选择音频
|
||||||
//fileIntent.setType(“video/*”); //选择视频 (mp4 3gp 是android支持的视频格式)
|
//fileIntent.setType(“video/*”); //选择视频 (mp4 3gp 是android支持的视频格式)
|
||||||
//fileIntent.setType(“video/*;image/*”);//同时选择视频和图片
|
//fileIntent.setType(“video/*;image/*”);//同时选择视频和图片
|
||||||
fileIntent.setType("*/*"); //无类型限制
|
fileIntent.setType("*/*"); //无类型限制
|
||||||
fileIntent.addCategory(Intent.CATEGORY_OPENABLE);
|
fileIntent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||||
main.startActivityForResult(fileIntent, 1);
|
main.startActivityForResult(fileIntent, 1);
|
||||||
// 获取回调
|
// 获取回调
|
||||||
main.onActivityResult = function (requestCode, resultCode, data) {
|
main.onActivityResult = function(requestCode, resultCode, data) {
|
||||||
let Activity = plus.android.importClass("android.app.Activity");
|
let Activity = plus.android.importClass("android.app.Activity");
|
||||||
let ContentUris = plus.android.importClass("android.content.ContentUris");
|
let ContentUris = plus.android.importClass("android.content.ContentUris");
|
||||||
let Cursor = plus.android.importClass("android.database.Cursor");
|
let Cursor = plus.android.importClass("android.database.Cursor");
|
||||||
let Uri = plus.android.importClass("android.net.Uri");
|
let Uri = plus.android.importClass("android.net.Uri");
|
||||||
let Build = plus.android.importClass("android.os.Build");
|
let Build = plus.android.importClass("android.os.Build");
|
||||||
let Environment = plus.android.importClass("android.os.Environment");
|
let Environment = plus.android.importClass("android.os.Environment");
|
||||||
let DocumentsContract = plus.android.importClass("android.provider.DocumentsContract");
|
let DocumentsContract = plus.android.importClass("android.provider.DocumentsContract");
|
||||||
let MediaStore = plus.android.importClass("android.provider.MediaStore");
|
let MediaStore = plus.android.importClass("android.provider.MediaStore");
|
||||||
// 给系统导入 contentResolver
|
// 给系统导入 contentResolver
|
||||||
let contentResolver = main.getContentResolver()
|
let contentResolver = main.getContentResolver()
|
||||||
plus.android.importClass(contentResolver);
|
plus.android.importClass(contentResolver);
|
||||||
// 返回路径
|
// 返回路径
|
||||||
let path = '';
|
let path = '';
|
||||||
if (resultCode == Activity.RESULT_OK) {
|
if (resultCode == Activity.RESULT_OK) {
|
||||||
let uri = data.getData()
|
let uri = data.getData()
|
||||||
if ("file" == uri.getScheme().toLowerCase()) { //使用第三方应用打开
|
|
||||||
path = uri.getPath();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) { //4.4以后
|
|
||||||
path = getPath(this, uri);
|
|
||||||
} else { //4.4以下下系统调用方法
|
|
||||||
path = getRealPathFromURI(uri)
|
|
||||||
}
|
|
||||||
// 回调
|
|
||||||
that.$emit('result', path)
|
|
||||||
}
|
|
||||||
// 4.4 以上 从Uri 获取文件绝对路径
|
|
||||||
function getPath(context, uri) {
|
|
||||||
let isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
|
|
||||||
let scheme = uri.getScheme().toLowerCase()
|
|
||||||
if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
|
|
||||||
// ExternalStorageProvider
|
|
||||||
if (isExternalStorageDocument(uri)) {
|
|
||||||
let docId = DocumentsContract.getDocumentId(uri);
|
|
||||||
let split = docId.split(":");
|
|
||||||
let type = split[0];
|
|
||||||
// 如果是手机内部存储
|
|
||||||
if ("primary" == type.toLowerCase()) {
|
|
||||||
return Environment.getExternalStorageDirectory() + "/" + split[1];
|
|
||||||
} else {
|
|
||||||
return '/storage/' + type + "/" + split[1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// DownloadsProvider
|
|
||||||
else if (isDownloadsDocument(uri)) {
|
|
||||||
let id = DocumentsContract.getDocumentId(uri);
|
|
||||||
let split = id.split(":");
|
|
||||||
return split[1]
|
|
||||||
// console.log(id)
|
|
||||||
// let contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), id);
|
|
||||||
// return getDataColumn(context, contentUri, null, null);
|
|
||||||
}
|
|
||||||
// MediaProvider
|
|
||||||
else if (isMediaDocument(uri)) {
|
|
||||||
let docId = DocumentsContract.getDocumentId(uri);
|
|
||||||
let split = docId.split(":");
|
|
||||||
let type = split[0];
|
|
||||||
let contentUri = null;
|
|
||||||
if ("image" == type.toLowerCase()) {
|
|
||||||
contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
|
|
||||||
} else if ("video" == type.toLowerCase()) {
|
|
||||||
contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
|
|
||||||
} else if ("audio" == type.toLowerCase()) {
|
|
||||||
contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
|
|
||||||
}
|
|
||||||
let selection = "_id=?";
|
|
||||||
let selectionArgs = [split[1]];
|
|
||||||
return getDataColumn(context, contentUri, selection, selectionArgs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// MediaStore (and general)
|
|
||||||
else if ("content" == scheme) {
|
|
||||||
return getDataColumn(context, uri, null, null);
|
|
||||||
}
|
|
||||||
// File
|
|
||||||
else if ("file" == scheme) {
|
|
||||||
return uri.getPath();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 4.4 以下 获取 绝对路径
|
|
||||||
function getRealPathFromURI(uri) {
|
|
||||||
let res = null
|
|
||||||
let proj = [MediaStore.Images.Media.DATA]
|
|
||||||
let cursor = contentResolver.query(uri, proj, null, null, null);
|
|
||||||
if (null != cursor && cursor.moveToFirst()) { ;
|
|
||||||
let column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
|
|
||||||
res = cursor.getString(column_index);
|
|
||||||
cursor.close();
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
// 通过uri 查找出绝对路径
|
|
||||||
function getDataColumn(context, uri, selection, selectionArgs) {
|
|
||||||
let cursor = null;
|
|
||||||
let column = "_data";
|
|
||||||
let projection = [column];
|
|
||||||
// let contentResolver = context.getContentResolver()
|
|
||||||
// plus.android.importClass(contentResolver);
|
|
||||||
cursor = contentResolver.query(uri, projection, selection, selectionArgs, null);
|
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
|
||||||
let column_index = cursor.getColumnIndexOrThrow(column);
|
|
||||||
return cursor.getString(column_index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function isExternalStorageDocument(uri) {
|
|
||||||
return "com.android.externalstorage.documents" == uri.getAuthority() ? true : false
|
|
||||||
}
|
|
||||||
function isDownloadsDocument(uri) {
|
|
||||||
return "com.android.providers.downloads.documents" == uri.getAuthority() ? true : false
|
|
||||||
}
|
|
||||||
function isMediaDocument(uri) {
|
|
||||||
return "com.android.providers.media.documents" == uri.getAuthority() ? true : false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// #endif
|
|
||||||
// #ifndef APP-PLUS
|
|
||||||
uni.showModal({
|
|
||||||
title: '提示',
|
|
||||||
content: '仅支持Android平台',
|
|
||||||
success: function (res) {
|
|
||||||
|
|
||||||
}
|
if ("file" == uri.getScheme().toLowerCase()) { //使用第三方应用打开
|
||||||
});
|
path = uri.getPath();
|
||||||
// #endif
|
return;
|
||||||
},
|
}
|
||||||
},
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) { //4.4以后
|
||||||
onLoad() {
|
path = getPath(this, uri);
|
||||||
// plus.io.resolveLocalFileSystemURL( '/storage/emulated/0', function(fs) {
|
} else { //4.4以下下系统调用方法
|
||||||
// var directoryReader = fs.createReader();
|
path = getRealPathFromURI(uri)
|
||||||
// directoryReader.readEntries(function(entries) {
|
}
|
||||||
// var i;
|
// 回调
|
||||||
// for (i = 0; i < entries.length; i++) {
|
that.$emit('result', path)
|
||||||
// console.log(entries[i].name);
|
}
|
||||||
// }
|
// 4.4 以上 从Uri 获取文件绝对路径
|
||||||
// }, function(e) {
|
function getPath(context, uri) {
|
||||||
// console.log("Read entries failed: " + e.message);
|
let isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
|
||||||
// });
|
let scheme = uri.getScheme().toLowerCase()
|
||||||
// }, function(e) {
|
|
||||||
// console.log("Request file system failed: " + e.message);
|
if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
|
||||||
// });
|
// ExternalStorageProvider
|
||||||
}
|
if (isExternalStorageDocument(uri)) {
|
||||||
}
|
let docId = DocumentsContract.getDocumentId(uri);
|
||||||
|
let split = docId.split(":");
|
||||||
|
let type = split[0];
|
||||||
|
// 如果是手机内部存储
|
||||||
|
if ("primary" == type.toLowerCase()) {
|
||||||
|
return Environment.getExternalStorageDirectory() + "/" + split[1];
|
||||||
|
} else {
|
||||||
|
return '/storage/' + type + "/" + split[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// DownloadsProvider
|
||||||
|
else if (isDownloadsDocument(uri)) {
|
||||||
|
let docId = DocumentsContract.getDocumentId(uri);
|
||||||
|
let split = docId.split(":");
|
||||||
|
return split[1]
|
||||||
|
// console.log(id)
|
||||||
|
// let contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), id);
|
||||||
|
// return getDataColumn(context, contentUri, null, null);
|
||||||
|
}
|
||||||
|
// MediaProvider
|
||||||
|
else if (isMediaDocument(uri)) {
|
||||||
|
let docId = DocumentsContract.getDocumentId(uri);
|
||||||
|
let split = docId.split(":");
|
||||||
|
let type = split[0];
|
||||||
|
let contentUri = null;
|
||||||
|
if ("image" == type.toLowerCase()) {
|
||||||
|
contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
|
||||||
|
} else if ("video" == type.toLowerCase()) {
|
||||||
|
contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
|
||||||
|
} else if ("audio" == type.toLowerCase()) {
|
||||||
|
contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
|
||||||
|
}
|
||||||
|
let selection = "_id=?";
|
||||||
|
let selectionArgs = [split[1]];
|
||||||
|
return getDataColumn(context, contentUri, selection, selectionArgs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// MediaStore (and general)
|
||||||
|
else if ("content" == scheme) {
|
||||||
|
return getDataColumn(context, uri, null, null);
|
||||||
|
}
|
||||||
|
// File
|
||||||
|
else if ("file" == scheme) {
|
||||||
|
return uri.getPath();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 4.4 以下 获取 绝对路径
|
||||||
|
function getRealPathFromURI(uri) {
|
||||||
|
let res = null
|
||||||
|
let proj = [MediaStore.Images.Media.DATA]
|
||||||
|
let cursor = contentResolver.query(uri, proj, null, null, null);
|
||||||
|
if (null != cursor && cursor.moveToFirst()) {
|
||||||
|
;
|
||||||
|
let column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
|
||||||
|
res = cursor.getString(column_index);
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
// 通过uri 查找出绝对路径
|
||||||
|
function getDataColumn(context, uri, selection, selectionArgs) {
|
||||||
|
let cursor = null;
|
||||||
|
let column = "_data";
|
||||||
|
let projection = [column];
|
||||||
|
// let contentResolver = context.getContentResolver()
|
||||||
|
// plus.android.importClass(contentResolver);
|
||||||
|
cursor = contentResolver.query(uri, projection, selection, selectionArgs, null);
|
||||||
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
|
let column_index = cursor.getColumnIndexOrThrow(column);
|
||||||
|
return cursor.getString(column_index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function isExternalStorageDocument(uri) {
|
||||||
|
return "com.android.externalstorage.documents" == uri.getAuthority() ? true : false
|
||||||
|
}
|
||||||
|
|
||||||
|
function isDownloadsDocument(uri) {
|
||||||
|
return "com.android.providers.downloads.documents" == uri.getAuthority() ? true : false
|
||||||
|
}
|
||||||
|
|
||||||
|
function isMediaDocument(uri) {
|
||||||
|
return "com.android.providers.media.documents" == uri.getAuthority() ? true : false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// #endif
|
||||||
|
// #ifndef APP-PLUS
|
||||||
|
uni.showModal({
|
||||||
|
title: '提示',
|
||||||
|
content: '仅支持Android平台',
|
||||||
|
success: function(res) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// #endif
|
||||||
|
},
|
||||||
|
},
|
||||||
|
onLoad() {
|
||||||
|
// plus.io.resolveLocalFileSystemURL( '/storage/emulated/0', function(fs) {
|
||||||
|
// var directoryReader = fs.createReader();
|
||||||
|
// directoryReader.readEntries(function(entries) {
|
||||||
|
// var i;
|
||||||
|
// for (i = 0; i < entries.length; i++) {
|
||||||
|
// console.log(entries[i].name);
|
||||||
|
// }
|
||||||
|
// }, function(e) {
|
||||||
|
// console.log("Read entries failed: " + e.message);
|
||||||
|
// });
|
||||||
|
// }, function(e) {
|
||||||
|
// console.log("Request file system failed: " + e.message);
|
||||||
|
// });
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
@@ -47,6 +47,7 @@
|
|||||||
"<uses-permission android:name=\"android.permission.INTERNET\"/>",
|
"<uses-permission android:name=\"android.permission.INTERNET\"/>",
|
||||||
"<uses-permission android:name=\"android.permission.MODIFY_AUDIO_SETTINGS\"/>",
|
"<uses-permission android:name=\"android.permission.MODIFY_AUDIO_SETTINGS\"/>",
|
||||||
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
|
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.READ_EXTERNAL_STORAGE\"/>",
|
||||||
"<uses-permission android:name=\"android.permission.READ_LOGS\"/>",
|
"<uses-permission android:name=\"android.permission.READ_LOGS\"/>",
|
||||||
"<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>",
|
"<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>",
|
||||||
"<uses-permission android:name=\"android.permission.RECORD_AUDIO\"/>",
|
"<uses-permission android:name=\"android.permission.RECORD_AUDIO\"/>",
|
||||||
@@ -112,33 +113,33 @@
|
|||||||
},
|
},
|
||||||
"icons" : {
|
"icons" : {
|
||||||
"android" : {
|
"android" : {
|
||||||
"hdpi" : "",
|
"hdpi" : "unpackage/res/icons/72x72.png",
|
||||||
"xhdpi" : "",
|
"xhdpi" : "unpackage/res/icons/96x96.png",
|
||||||
"xxhdpi" : "",
|
"xxhdpi" : "unpackage/res/icons/144x144.png",
|
||||||
"xxxhdpi" : ""
|
"xxxhdpi" : "unpackage/res/icons/192x192.png"
|
||||||
},
|
},
|
||||||
"ios" : {
|
"ios" : {
|
||||||
"appstore" : "",
|
"appstore" : "unpackage/res/icons/1024x1024.png",
|
||||||
"ipad" : {
|
"ipad" : {
|
||||||
"app" : "",
|
"app" : "unpackage/res/icons/76x76.png",
|
||||||
"app@2x" : "",
|
"app@2x" : "unpackage/res/icons/152x152.png",
|
||||||
"notification" : "",
|
"notification" : "unpackage/res/icons/20x20.png",
|
||||||
"notification@2x" : "",
|
"notification@2x" : "unpackage/res/icons/40x40.png",
|
||||||
"proapp@2x" : "",
|
"proapp@2x" : "unpackage/res/icons/167x167.png",
|
||||||
"settings" : "",
|
"settings" : "unpackage/res/icons/29x29.png",
|
||||||
"settings@2x" : "",
|
"settings@2x" : "unpackage/res/icons/58x58.png",
|
||||||
"spotlight" : "",
|
"spotlight" : "unpackage/res/icons/40x40.png",
|
||||||
"spotlight@2x" : ""
|
"spotlight@2x" : "unpackage/res/icons/80x80.png"
|
||||||
},
|
},
|
||||||
"iphone" : {
|
"iphone" : {
|
||||||
"app@2x" : "",
|
"app@2x" : "unpackage/res/icons/120x120.png",
|
||||||
"app@3x" : "",
|
"app@3x" : "unpackage/res/icons/180x180.png",
|
||||||
"notification@2x" : "",
|
"notification@2x" : "unpackage/res/icons/40x40.png",
|
||||||
"notification@3x" : "",
|
"notification@3x" : "unpackage/res/icons/60x60.png",
|
||||||
"settings@2x" : "",
|
"settings@2x" : "unpackage/res/icons/58x58.png",
|
||||||
"settings@3x" : "",
|
"settings@3x" : "unpackage/res/icons/87x87.png",
|
||||||
"spotlight@2x" : "",
|
"spotlight@2x" : "unpackage/res/icons/80x80.png",
|
||||||
"spotlight@3x" : ""
|
"spotlight@3x" : "unpackage/res/icons/120x120.png"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
<text class="text">文件</text>
|
<text class="text">文件</text>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<tki-file-manager ref="filemanager" @result="resultPath"></tki-file-manager>
|
<tki-file-manager ref="filemanager" @result="sendFileMessage"></tki-file-manager>
|
||||||
|
|
||||||
<u-action-sheet :actions="callActions" cancelText="取消" @close="callShow = false" @select="singleCall"
|
<u-action-sheet :actions="callActions" cancelText="取消" @close="callShow = false" @select="singleCall"
|
||||||
:show="callShow">
|
:show="callShow">
|
||||||
@@ -42,9 +42,9 @@
|
|||||||
mixins: [
|
mixins: [
|
||||||
imBase
|
imBase
|
||||||
],
|
],
|
||||||
components: [
|
components: {
|
||||||
tkiFileManager
|
tkiFileManager
|
||||||
],
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
callActions: [{
|
callActions: [{
|
||||||
@@ -74,10 +74,22 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
resultPath(path) {
|
sendFileMessage(path) {
|
||||||
im.sentFile(this.conversationType, this.targetId, path).then(res => {
|
if (path) {
|
||||||
console.log('发送文件', res);
|
im.sentFile(this.conversationType, this.targetId, path).then(res => {
|
||||||
})
|
this.success()
|
||||||
|
}).catch(err => {
|
||||||
|
uni.showToast({
|
||||||
|
icon: 'none',
|
||||||
|
title: '发送文件失败' + err
|
||||||
|
})
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
uni.showToast({
|
||||||
|
icon: 'none',
|
||||||
|
title: '选择文件失败'
|
||||||
|
})
|
||||||
|
}
|
||||||
},
|
},
|
||||||
singleCall(e) {
|
singleCall(e) {
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
@@ -120,8 +132,10 @@
|
|||||||
break;
|
break;
|
||||||
case 'location':
|
case 'location':
|
||||||
uni.chooseLocation({
|
uni.chooseLocation({
|
||||||
success: (c) => {
|
success: (location) => {
|
||||||
console.log(c);
|
im.sentLocation(this.conversationType, this.targetId, location).then(() => {
|
||||||
|
this.success()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
break;
|
break;
|
||||||
@@ -133,11 +147,6 @@
|
|||||||
break;
|
break;
|
||||||
case 'file':
|
case 'file':
|
||||||
this.$refs.filemanager._openFile()
|
this.$refs.filemanager._openFile()
|
||||||
|
|
||||||
// uni.showToast({
|
|
||||||
// icon: 'none',
|
|
||||||
// title: '功能正在开发中'
|
|
||||||
// })
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
95
pages/im/components/show/showFile.vue
Normal file
95
pages/im/components/show/showFile.vue
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
<template>
|
||||||
|
<view class="msg--file">
|
||||||
|
<message-state :message="message" :isGroup="isGroup" :isRemote="isRemote" />
|
||||||
|
|
||||||
|
<view class="">
|
||||||
|
<view class="name" v-if="isGroup && isRemote">{{ contact(message.senderUserId).name }}</view>
|
||||||
|
<view class="file" :class="isRemote ? 'left': 'right'">
|
||||||
|
<view class="img">
|
||||||
|
{{ content.fileType }}
|
||||||
|
{{ content.name }}
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<!-- "content": {
|
||||||
|
"fileType": "jpg",
|
||||||
|
"remote": "https://rongcloud-spic.ronghub.com/Xl1PRVpHVldeRQAGVgEHAAcBBgYGBgcDAwMGMjA3MA%3D%3D.jpg?e=1661583313&token=livk5rb3__JZjCtEiMxXpQ8QscLxbNLehwhHySnX:t58hs4uvM1RFsBeKLTcDbVW-k5w=",
|
||||||
|
"size": 347062,
|
||||||
|
"objectName": "RC:FileMsg",
|
||||||
|
"name": "Screenshot_2022-02-25-14-44-55-886_io.zhhealth.app.jpg",
|
||||||
|
"local": "file:///storage/emulated/0/DCIM/Screenshots/Screenshot_2022-02-25-14-44-55-886_io.zhhealth.app.jpg",
|
||||||
|
"userInfo": {
|
||||||
|
"userId": "10051",
|
||||||
|
"name": "Jason.电信",
|
||||||
|
"extra": "",
|
||||||
|
"portraitUrl": "http://storage.zh.shangkelian.cn/uploads/2022/02/16/29b13f5301694721ad7acd8b8b67bbd9.jpg"
|
||||||
|
}
|
||||||
|
}, -->
|
||||||
|
<script>
|
||||||
|
import * as RongIMLib from '@/uni_modules/RongCloud-IMWrapper/js_sdk/index'
|
||||||
|
import messageState from './messageState'
|
||||||
|
import imBase from '../../mixins/imBase.js'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
mixins: [
|
||||||
|
imBase
|
||||||
|
],
|
||||||
|
props: {
|
||||||
|
message: {
|
||||||
|
type: Object,
|
||||||
|
default: () => {
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
isGroup: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
components: {
|
||||||
|
messageState
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
isRemote() {
|
||||||
|
return this.message.messageDirection == 2
|
||||||
|
},
|
||||||
|
content() {
|
||||||
|
return this.message.content
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.msg--file {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-end;
|
||||||
|
|
||||||
|
.name {
|
||||||
|
font-size: 24rpx;
|
||||||
|
color: $text-gray-m;
|
||||||
|
}
|
||||||
|
|
||||||
|
.file {
|
||||||
|
.img {
|
||||||
|
width: 180rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.left {
|
||||||
|
.img {
|
||||||
|
border-radius: 0 10rpx 10rpx 10rpx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&.right {
|
||||||
|
.img {
|
||||||
|
border-radius: 10rpx 0 10rpx 10rpx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
</style>
|
||||||
86
pages/im/components/show/showLocation.vue
Normal file
86
pages/im/components/show/showLocation.vue
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
<template>
|
||||||
|
<view class="msg--location">
|
||||||
|
<message-state :message="message" :isGroup="isGroup" :isRemote="isRemote" />
|
||||||
|
|
||||||
|
<view class="">
|
||||||
|
<view class="name" v-if="isGroup && isRemote">{{ contact(message.senderUserId).name }}</view>
|
||||||
|
<view class="location" :class="isRemote ? 'left': 'right'" @click="showLocation">
|
||||||
|
{{ content.customFields.name }}
|
||||||
|
{{ content.customFields.thumbnail }}
|
||||||
|
<!-- 缩略图,在考虑是否要通过截图后自动截屏来操作 -->
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import * as RongIMLib from '@/uni_modules/RongCloud-IMWrapper/js_sdk/index'
|
||||||
|
import messageState from './messageState'
|
||||||
|
import imBase from '../../mixins/imBase.js'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
mixins: [
|
||||||
|
imBase
|
||||||
|
],
|
||||||
|
name: 'showImage',
|
||||||
|
props: {
|
||||||
|
message: {
|
||||||
|
type: Object,
|
||||||
|
default: () => {
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
isGroup: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
components: {
|
||||||
|
messageState
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
isRemote() {
|
||||||
|
return this.message.messageDirection == 2
|
||||||
|
},
|
||||||
|
content() {
|
||||||
|
return this.message.content
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
showLocation() {
|
||||||
|
console.log(this.content.customFields.longitude, this.content.customFields.latitude)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
.msg--location {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-end;
|
||||||
|
|
||||||
|
.name {
|
||||||
|
font-size: 24rpx;
|
||||||
|
color: $text-gray-m;
|
||||||
|
}
|
||||||
|
|
||||||
|
.location {
|
||||||
|
.image {
|
||||||
|
width: 180rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.left {
|
||||||
|
.image {
|
||||||
|
border-radius: 0 10rpx 10rpx 10rpx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&.right {
|
||||||
|
.image {
|
||||||
|
border-radius: 10rpx 0 10rpx 10rpx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
30
pages/im/components/show/showNormal.vue
Normal file
30
pages/im/components/show/showNormal.vue
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<template>
|
||||||
|
<view class="">
|
||||||
|
<show-location v-if="message.content.objectName == 'RC:LBSMsg'" :message="message" :isGroup="isGroup" />
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import showLocation from './showLocation'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
props: {
|
||||||
|
message: {
|
||||||
|
type: Object,
|
||||||
|
default: () => {
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
isGroup: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
components: {
|
||||||
|
showLocation
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
</style>
|
||||||
@@ -16,6 +16,9 @@
|
|||||||
<show-voice v-else-if="message.objectName === 'RC:HQVCMsg'" :message="message" :isGroup="isGroup" />
|
<show-voice v-else-if="message.objectName === 'RC:HQVCMsg'" :message="message" :isGroup="isGroup" />
|
||||||
<show-image v-else-if="message.objectName === 'RC:ImgMsg'" :message="message" :isGroup="isGroup" />
|
<show-image v-else-if="message.objectName === 'RC:ImgMsg'" :message="message" :isGroup="isGroup" />
|
||||||
<show-call v-else-if="message.objectName === 'RC:InfoNtf'" :message="message" :isGroup="isGroup" />
|
<show-call v-else-if="message.objectName === 'RC:InfoNtf'" :message="message" :isGroup="isGroup" />
|
||||||
|
<show-file v-else-if="message.objectName === 'RC:FileMsg'" :message="message" :isGroup="isGroup" />
|
||||||
|
<show-normal v-else-if="message.objectName === 'RC:IWNormalMsg'" :message="message" :isGroup="isGroup" />
|
||||||
|
|
||||||
<view v-else class="">
|
<view v-else class="">
|
||||||
[未处理的消息类型 {{ message.objectName }}]
|
[未处理的消息类型 {{ message.objectName }}]
|
||||||
</view>
|
</view>
|
||||||
@@ -34,6 +37,8 @@
|
|||||||
import showImage from './show/showImage'
|
import showImage from './show/showImage'
|
||||||
import showText from './show/showText'
|
import showText from './show/showText'
|
||||||
import showCall from './show/showCall'
|
import showCall from './show/showCall'
|
||||||
|
import showFile from './show/showFile'
|
||||||
|
import showNormal from './show/showNormal'
|
||||||
import utils from '@/utils/index.js'
|
import utils from '@/utils/index.js'
|
||||||
import imBase from '../mixins/imBase.js'
|
import imBase from '../mixins/imBase.js'
|
||||||
|
|
||||||
@@ -45,7 +50,9 @@
|
|||||||
showCall,
|
showCall,
|
||||||
showVoice,
|
showVoice,
|
||||||
showImage,
|
showImage,
|
||||||
showText
|
showText,
|
||||||
|
showFile,
|
||||||
|
showNormal
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
message: {
|
message: {
|
||||||
|
|||||||
@@ -163,6 +163,7 @@
|
|||||||
10,
|
10,
|
||||||
false,
|
false,
|
||||||
(messages) => {
|
(messages) => {
|
||||||
|
console.log('获取最新消息', messages);
|
||||||
this.messages.unshift(...messages)
|
this.messages.unshift(...messages)
|
||||||
this.scrollBottom()
|
this.scrollBottom()
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -107,7 +107,7 @@
|
|||||||
conversations
|
conversations
|
||||||
}) => {
|
}) => {
|
||||||
if (code === 0) {
|
if (code === 0) {
|
||||||
console.log(conversations,',,,,,')
|
console.log('获取会话列表', conversations);
|
||||||
this.conversations = conversations
|
this.conversations = conversations
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -55,7 +55,8 @@ const notifyMsgTypes = [
|
|||||||
IMLib.ObjectName.Location,
|
IMLib.ObjectName.Location,
|
||||||
IMLib.ObjectName.Voice,
|
IMLib.ObjectName.Voice,
|
||||||
IMLib.ObjectName.HQVoice,
|
IMLib.ObjectName.HQVoice,
|
||||||
IMLib.ObjectName.Sight
|
IMLib.ObjectName.Sight,
|
||||||
|
'RC:IWNormalMsg'
|
||||||
]
|
]
|
||||||
|
|
||||||
const imLibListeners = () => {
|
const imLibListeners = () => {
|
||||||
|
|||||||
@@ -18,7 +18,8 @@ const getMessageList = (conversationType, targetId, timeStamp, count, isForward,
|
|||||||
'RC:CombineMsg',
|
'RC:CombineMsg',
|
||||||
'RC:GrpNtf',
|
'RC:GrpNtf',
|
||||||
'RC:InfoNtf',
|
'RC:InfoNtf',
|
||||||
'RC:RcNtf'
|
'RC:RcNtf',
|
||||||
|
'RC:IWNormalMsg'
|
||||||
]
|
]
|
||||||
|
|
||||||
RongIMLib.getHistoryMessagesByTimestamp(
|
RongIMLib.getHistoryMessagesByTimestamp(
|
||||||
@@ -184,10 +185,13 @@ const sentFile = (conversationType, targetId, fileUrl) => {
|
|||||||
targetId: String(targetId),
|
targetId: String(targetId),
|
||||||
content: {
|
content: {
|
||||||
objectName: 'RC:FileMsg',
|
objectName: 'RC:FileMsg',
|
||||||
local: 'file:///' + plus.io.convertLocalFileSystemURL(fileUrl),
|
local: plus.io.convertLocalFileSystemURL(fileUrl),
|
||||||
userInfo: store.getters.sender
|
userInfo: store.getters.sender
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('发送文件', msg);
|
||||||
|
|
||||||
RongIMLib.sendMediaMessage(msg, {
|
RongIMLib.sendMediaMessage(msg, {
|
||||||
success: (messageId) => {
|
success: (messageId) => {
|
||||||
resolve(messageId)
|
resolve(messageId)
|
||||||
@@ -201,6 +205,48 @@ const sentFile = (conversationType, targetId, fileUrl) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 发送地理位置
|
||||||
|
const sentLocation = (conversationType, targetId, location) => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const msg = {
|
||||||
|
conversationType: conversationType,
|
||||||
|
targetId: String(targetId),
|
||||||
|
objectName: 'RC:LBSMsg',
|
||||||
|
content: {
|
||||||
|
customType: 2,
|
||||||
|
objectName: 'RC:LBSMsg',
|
||||||
|
customFields: {
|
||||||
|
name: location.name,
|
||||||
|
latitude: Number(location.latitude),
|
||||||
|
longitude: Number(location.longitude),
|
||||||
|
thumbnail: ''
|
||||||
|
},
|
||||||
|
userInfo: store.getters.sender,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RongIMLib.sendMessage(msg, ({
|
||||||
|
code,
|
||||||
|
messageId
|
||||||
|
}) => {
|
||||||
|
if (code === 0) {
|
||||||
|
if (conversationType == 3) {
|
||||||
|
RongIMLib.sendReadReceiptRequest(messageId, (res) => {
|
||||||
|
console.log('发送回执请求', res);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
resolve(messageId)
|
||||||
|
} else {
|
||||||
|
uni.showToast({
|
||||||
|
icon: 'none',
|
||||||
|
title: '发送失败' + code
|
||||||
|
})
|
||||||
|
reject(code)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
getMessageList,
|
getMessageList,
|
||||||
getPendingList,
|
getPendingList,
|
||||||
@@ -208,5 +254,6 @@ export default {
|
|||||||
sentText,
|
sentText,
|
||||||
sentVoice,
|
sentVoice,
|
||||||
sentImage,
|
sentImage,
|
||||||
sentFile
|
sentFile,
|
||||||
|
sentLocation
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user