Commit 6476e76f by Sixong.Zhu

调整缩约图

parent de39e602
import { MessageType } from "@/customer-service/model"; import { MessageType } from "@/customer-service/model";
import { CardMessage } from '@/customer-service/model/card'; import { CardMessage } from "@/customer-service/model/card";
import Chat from "@/customer-service/xim";
const fsImg = /(fs(.*))/;
const mapping = new Map<MessageType, string>([ const mapping = new Map<MessageType, string>([
[MessageType.Image, '图片'], [MessageType.Image, "图片"],
[MessageType.Video, '视频'], [MessageType.Video, "视频"],
[MessageType.Voice, '语音'], [MessageType.Voice, "语音"],
[MessageType.File, '文件'], [MessageType.File, "文件"],
[MessageType.Withdraw, '撤回了一条消息'], [MessageType.Withdraw, "撤回了一条消息"],
[MessageType.MyPurchasePlan, '我的采购计划'], [MessageType.MyPurchasePlan, "我的采购计划"],
[MessageType.MyWelfare, '我的福利'], [MessageType.MyWelfare, "我的福利"],
[MessageType.QuestionAnswer, '问答'], [MessageType.QuestionAnswer, "问答"],
[MessageType.Pay, '付款通知'], [MessageType.Pay, "付款通知"],
[MessageType.PayV1, '付款通知'], [MessageType.PayV1, "付款通知"],
[MessageType.Refund, '退款通知'], [MessageType.Refund, "退款通知"],
[MessageType.RefundV1, '退款通知'], [MessageType.RefundV1, "退款通知"],
[MessageType.Notify, '通知'], [MessageType.Notify, "通知"],
]) ]);
export function parserMessage(type: MessageType, rawMsg: string) { export function parserMessage(type: MessageType, rawMsg: string) {
try { try {
...@@ -35,15 +38,28 @@ export function parserMessage(type: MessageType, rawMsg: string) { ...@@ -35,15 +38,28 @@ export function parserMessage(type: MessageType, rawMsg: string) {
if (type === MessageType.Card) { if (type === MessageType.Card) {
const p = JSON.parse(rawMsg) as CardMessage; const p = JSON.parse(rawMsg) as CardMessage;
if (p && p.title) { if (p && p.title) {
return p.title || '通知'; return p.title || "通知";
} }
} }
const t = mapping.get(type) const t = mapping.get(type);
if (t) { if (t) {
return `[${t}]`; return `[${t}]`;
} }
return `[系统自动回复]`; return `[系统自动回复]`;
} catch { } catch {
return "" return "";
}
}
export function rebuildImage(url: string) {
if (url) {
const sdk = Chat.getSdk();
const s = sdk.mediaController.buildThumbnail;
if (fsImg.test(url)) {
const m = fsImg.exec(url);
return sdk.global.baseUrl + s(m[0], 300);
}
return url;
} }
return "";
} }
...@@ -22,9 +22,7 @@ ...@@ -22,9 +22,7 @@
import BaseMessage from "./index"; import BaseMessage from "./index";
import FileIcon from "./file-icon.vue"; import FileIcon from "./file-icon.vue";
import { UserAgentHelper } from "@/customer-service/third-party/user-agent"; import { UserAgentHelper } from "@/customer-service/third-party/user-agent";
import Chat from "@/customer-service/xim/"; import { rebuildImage } from "../controller";
const fsImg = /(fs(.*))/;
@Component({ components: { FileIcon } }) @Component({ components: { FileIcon } })
export default class Index extends BaseMessage { export default class Index extends BaseMessage {
...@@ -35,16 +33,7 @@ ...@@ -35,16 +33,7 @@
); );
private get mini() { private get mini() {
if (this.messageRealUrl) { return rebuildImage(this.messageRealUrl);
const sdk = Chat.getSdk();
const s = sdk.mediaController.buildThumbnail;
if (fsImg.test(this.messageRealUrl)) {
const m = fsImg.exec(this.messageRealUrl);
return sdk.global.baseUrl + s(m[0], 300);
}
return this.messageRealUrl;
}
return "";
} }
private onImageError() { private onImageError() {
......
...@@ -21,6 +21,7 @@ import { decodeJwt } from "uniplat-sdk"; ...@@ -21,6 +21,7 @@ import { decodeJwt } from "uniplat-sdk";
import { ChatStatus, ChatStore, ChatStoreState } from "./model"; import { ChatStatus, ChatStore, ChatStoreState } from "./model";
import { RootStoreState } from "@/store/model"; import { RootStoreState } from "@/store/model";
import { rebuildImage } from "../components/controller";
export const ns = ChatStore.ns; export const ns = ChatStore.ns;
...@@ -71,7 +72,7 @@ async function preCacheImgs(msgs?: any[]) { ...@@ -71,7 +72,7 @@ async function preCacheImgs(msgs?: any[]) {
typeof Image !== "undefined" typeof Image !== "undefined"
) { ) {
const preCache = new Image(); const preCache = new Image();
preCache.src = url; preCache.src = rebuildImage(url);
preCache.onload = () => resolve(); preCache.onload = () => resolve();
setTimeout(resolve, 2000); setTimeout(resolve, 2000);
} else { } else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment