diff --git a/jiuyi2/common/js/util.js b/jiuyi2/common/js/util.js index a6ca6a00..87569885 100644 --- a/jiuyi2/common/js/util.js +++ b/jiuyi2/common/js/util.js @@ -580,36 +580,34 @@ const util = { * @param {Array} obj.sourceType ['album', 'camera'] * @param {Function} obj.success 执行成功返回的方法return修改的对象 */ - upload_image(obj) { - // 格式化默认值 + upload_image(obj) { // 格式化默认值 // 图片计数 - const count = obj.count ? obj.count : 8 + const count = obj.count ? obj.count : 8; // 多张图片 - if (!obj.type) obj.type = 2 + if (!obj.type) obj.type = 2; // 操作对象 - if (obj.value != '' && obj.value == undefined && obj.value == null) obj.value = obj.type == 1 ? '' : [] + // 修正逻辑判断 + if (obj.value == '' || obj.value == undefined || obj.value == null) obj.value = obj.type == 1 ? '' : []; // 判断剩余图片上传个数 if (obj.value.length >= count && obj.type == 2) { // 弹窗提示 - util.alert('上传图片已达上限') - return + util.alert('上传图片已达上限'); + return; } - let sourceType = ['album', 'camera'] - // 选择图片 uni.chooseImage({ // 限制图片 count: obj.type == 1 ? 1 : count - obj.value.length, - sourceType: obj.sourceType || sourceType, + sourceType: obj.sourceType || ['album', 'camera'], success: (rs) => { // 遍历图片返回列表 rs.tempFiles.forEach(item => { // 限制大小 - let size = 1024 * 1024 * util.config.img_size + let size = 1024 * 1024 * util.config.img_size; if (item.size > size && !obj.unlimited) { - util.alert(`大小超过${util.config.img_size}m`) - return + util.alert(`大小超过${util.config.img_size}m`); + return; } // 调用上传图片 util.upload({ @@ -618,29 +616,29 @@ const util = { success(res) { // 上传成功 if (res.code === 200) { - const result = res.data.url + const result = res.data.url; // 补全路径赋值 if (obj.type == 2) { - obj.value.push(result) + obj.value.push(result); } else if (obj.type == 1) { - obj.value = result + obj.value = result; } obj.success && obj.success({ value: result, - }) - return + }); + return; } - util.alert(rs.msg) + util.alert(rs.msg); }, - }) - }) + }); + }); }, fail(rs) { if (rs.errMsg == "chooseImage:fail cancel") { // 取消选择 } }, - }) + }); }, /** diff --git a/jiuyi2/pages/news/chat/chat.vue b/jiuyi2/pages/news/chat/chat.vue index add8da1c..80cd9fb5 100644 --- a/jiuyi2/pages/news/chat/chat.vue +++ b/jiuyi2/pages/news/chat/chat.vue @@ -151,7 +151,7 @@ // 获取第一条消息记录 if (list.total <= list.data.length) return getHistory({ - param: list.data[0].id + msgId: list.data[0].id }) } @@ -246,7 +246,7 @@ // 监听内容滚动 function onContentScroll(ev) { - if (ev.scrollTop == 0) getMoreHistroy() + if (ev.scrollTop == 50) getMoreHistroy() debounce(() => { top.value = ev.detail.scrollTop }) @@ -275,10 +275,7 @@ * @param {Object} message 消息对象 */ function handlePlusSend(message) { - console.log('handlePlusSend', message) - sendMsg({ - message, - }) + sendMsg(message) } /** diff --git a/jiuyi2/pages/news/chat/jy-plus.vue b/jiuyi2/pages/news/chat/jy-plus.vue index 3fa3ee75..4d8b2a29 100644 --- a/jiuyi2/pages/news/chat/jy-plus.vue +++ b/jiuyi2/pages/news/chat/jy-plus.vue @@ -130,6 +130,7 @@ //拍照 takePhoto: () => { + console.log('takePhoto') sendMsgImg({ sourceType: ['album'], }) @@ -137,6 +138,7 @@ //选择图片 chooseImage: () => { + console.log('chooseImage') sendMsgImg({ sourceType: ['album'], }) @@ -145,10 +147,25 @@ // 发送图片消息 function sendMsgImg(option) { + util.upload_image({ + count: 1, + type: 1, + success: rs => { + emit('send', { + query: { + toUserId: props.msg.id, + msgType: TencentCloudChat.TYPES.MSG_IMAGE, + }, + data: { + imgUrl: rs.value + }, + }) + } + }) + return // 选择图片 uni.chooseImage({ count: 1, - sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有 sourceType: option.sourceType, // 从相册选择 success: (res) => { let message = uni.$chat.createImageMessage({ @@ -161,7 +178,6 @@ console.log('file uploading:', event) } }) - emit('send', message) return } }); diff --git a/jiuyi2/vite.config.js b/jiuyi2/vite.config.js index da97fe9c..db8ad4ad 100644 --- a/jiuyi2/vite.config.js +++ b/jiuyi2/vite.config.js @@ -15,22 +15,26 @@ export default defineConfig({ }, "/user": { // target: "http://192.168.0.129:8080", - target: "http://192.168.1.199:8080", + // target: "http://192.168.1.199:8080", + target: "http://192.168.0.133:8080", changeOrigin: true, }, "/coreplay": { // target: "http://192.168.0.129:8080", - target: "http://192.168.1.199:8080", + // target: "http://192.168.1.199:8080", + target: "http://192.168.0.133:8080", changeOrigin: true, }, "/file": { // target: "http://192.168.0.129:8080", - target: "http://192.168.1.199:8080", + // target: "http://192.168.1.199:8080", + target: "http://192.168.0.133:8080", changeOrigin: true, }, "/video": { // target: "http://192.168.0.129:8080", - target: "http://192.168.1.199:8080", + // target: "http://192.168.1.199:8080", + target: "http://192.168.0.133:8080", changeOrigin: true, }, }