diff --git a/components/tki-file-manager/tki-file-manager.vue b/components/tki-file-manager/tki-file-manager.vue index 5ee1634..2d1f0c3 100644 --- a/components/tki-file-manager/tki-file-manager.vue +++ b/components/tki-file-manager/tki-file-manager.vue @@ -1,183 +1,188 @@ \ No newline at end of file + 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 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); + // }); + } + } + diff --git a/manifest.json b/manifest.json index 3153cbb..66c6eac 100644 --- a/manifest.json +++ b/manifest.json @@ -47,6 +47,7 @@ "", "", "", + "", "", "", "", @@ -112,33 +113,33 @@ }, "icons" : { "android" : { - "hdpi" : "", - "xhdpi" : "", - "xxhdpi" : "", - "xxxhdpi" : "" + "hdpi" : "unpackage/res/icons/72x72.png", + "xhdpi" : "unpackage/res/icons/96x96.png", + "xxhdpi" : "unpackage/res/icons/144x144.png", + "xxxhdpi" : "unpackage/res/icons/192x192.png" }, "ios" : { - "appstore" : "", + "appstore" : "unpackage/res/icons/1024x1024.png", "ipad" : { - "app" : "", - "app@2x" : "", - "notification" : "", - "notification@2x" : "", - "proapp@2x" : "", - "settings" : "", - "settings@2x" : "", - "spotlight" : "", - "spotlight@2x" : "" + "app" : "unpackage/res/icons/76x76.png", + "app@2x" : "unpackage/res/icons/152x152.png", + "notification" : "unpackage/res/icons/20x20.png", + "notification@2x" : "unpackage/res/icons/40x40.png", + "proapp@2x" : "unpackage/res/icons/167x167.png", + "settings" : "unpackage/res/icons/29x29.png", + "settings@2x" : "unpackage/res/icons/58x58.png", + "spotlight" : "unpackage/res/icons/40x40.png", + "spotlight@2x" : "unpackage/res/icons/80x80.png" }, "iphone" : { - "app@2x" : "", - "app@3x" : "", - "notification@2x" : "", - "notification@3x" : "", - "settings@2x" : "", - "settings@3x" : "", - "spotlight@2x" : "", - "spotlight@3x" : "" + "app@2x" : "unpackage/res/icons/120x120.png", + "app@3x" : "unpackage/res/icons/180x180.png", + "notification@2x" : "unpackage/res/icons/40x40.png", + "notification@3x" : "unpackage/res/icons/60x60.png", + "settings@2x" : "unpackage/res/icons/58x58.png", + "settings@3x" : "unpackage/res/icons/87x87.png", + "spotlight@2x" : "unpackage/res/icons/80x80.png", + "spotlight@3x" : "unpackage/res/icons/120x120.png" } } }, diff --git a/pages/im/components/sent/sentPopups.vue b/pages/im/components/sent/sentPopups.vue index 87c025a..b847a97 100644 --- a/pages/im/components/sent/sentPopups.vue +++ b/pages/im/components/sent/sentPopups.vue @@ -25,7 +25,7 @@ 文件 - + @@ -42,9 +42,9 @@ mixins: [ imBase ], - components: [ + components: { tkiFileManager - ], + }, data() { return { callActions: [{ @@ -74,10 +74,22 @@ } }, methods: { - resultPath(path) { - im.sentFile(this.conversationType, this.targetId, path).then(res => { - console.log('发送文件', res); - }) + sendFileMessage(path) { + if (path) { + 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) { uni.navigateTo({ @@ -120,8 +132,10 @@ break; case 'location': uni.chooseLocation({ - success: (c) => { - console.log(c); + success: (location) => { + im.sentLocation(this.conversationType, this.targetId, location).then(() => { + this.success() + }) } }) break; @@ -133,11 +147,6 @@ break; case 'file': this.$refs.filemanager._openFile() - - // uni.showToast({ - // icon: 'none', - // title: '功能正在开发中' - // }) break; } }, diff --git a/pages/im/components/show/showFile.vue b/pages/im/components/show/showFile.vue new file mode 100644 index 0000000..56e4951 --- /dev/null +++ b/pages/im/components/show/showFile.vue @@ -0,0 +1,95 @@ + + + + + + diff --git a/pages/im/components/show/showLocation.vue b/pages/im/components/show/showLocation.vue new file mode 100644 index 0000000..dbb74fb --- /dev/null +++ b/pages/im/components/show/showLocation.vue @@ -0,0 +1,86 @@ + + + + + diff --git a/pages/im/components/show/showNormal.vue b/pages/im/components/show/showNormal.vue new file mode 100644 index 0000000..3b7ee73 --- /dev/null +++ b/pages/im/components/show/showNormal.vue @@ -0,0 +1,30 @@ + + + + + diff --git a/pages/im/components/showMessageCell.vue b/pages/im/components/showMessageCell.vue index 0aed87b..86cad0c 100644 --- a/pages/im/components/showMessageCell.vue +++ b/pages/im/components/showMessageCell.vue @@ -15,7 +15,10 @@ - + + + + [未处理的消息类型 {{ message.objectName }}] @@ -34,6 +37,8 @@ import showImage from './show/showImage' import showText from './show/showText' import showCall from './show/showCall' + import showFile from './show/showFile' + import showNormal from './show/showNormal' import utils from '@/utils/index.js' import imBase from '../mixins/imBase.js' @@ -45,8 +50,10 @@ showCall, showVoice, showImage, - showText - }, + showText, + showFile, + showNormal + }, props: { message: { type: Object, diff --git a/pages/im/group/chat.vue b/pages/im/group/chat.vue index ea4661a..af8ff80 100644 --- a/pages/im/group/chat.vue +++ b/pages/im/group/chat.vue @@ -163,6 +163,7 @@ 10, false, (messages) => { + console.log('获取最新消息', messages); this.messages.unshift(...messages) this.scrollBottom() }) diff --git a/pages/im/index.vue b/pages/im/index.vue index 344ef48..55a7a07 100644 --- a/pages/im/index.vue +++ b/pages/im/index.vue @@ -106,8 +106,8 @@ code, conversations }) => { - if (code === 0) { - console.log(conversations,',,,,,') + if (code === 0) { + console.log('获取会话列表', conversations); this.conversations = conversations } }) diff --git a/utils/im/listeners.js b/utils/im/listeners.js index 62c6efc..5250e05 100644 --- a/utils/im/listeners.js +++ b/utils/im/listeners.js @@ -55,7 +55,8 @@ const notifyMsgTypes = [ IMLib.ObjectName.Location, IMLib.ObjectName.Voice, IMLib.ObjectName.HQVoice, - IMLib.ObjectName.Sight + IMLib.ObjectName.Sight, + 'RC:IWNormalMsg' ] const imLibListeners = () => { diff --git a/utils/im/message.js b/utils/im/message.js index 76d37d0..286a988 100644 --- a/utils/im/message.js +++ b/utils/im/message.js @@ -18,7 +18,8 @@ const getMessageList = (conversationType, targetId, timeStamp, count, isForward, 'RC:CombineMsg', 'RC:GrpNtf', 'RC:InfoNtf', - 'RC:RcNtf' + 'RC:RcNtf', + 'RC:IWNormalMsg' ] RongIMLib.getHistoryMessagesByTimestamp( @@ -184,10 +185,13 @@ const sentFile = (conversationType, targetId, fileUrl) => { targetId: String(targetId), content: { objectName: 'RC:FileMsg', - local: 'file:///' + plus.io.convertLocalFileSystemURL(fileUrl), + local: plus.io.convertLocalFileSystemURL(fileUrl), userInfo: store.getters.sender } } + + console.log('发送文件', msg); + RongIMLib.sendMediaMessage(msg, { success: (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 { getMessageList, getPendingList, @@ -208,5 +254,6 @@ export default { sentText, sentVoice, sentImage, - sentFile + sentFile, + sentLocation }