yanzhen-design-vue
Version:
197 lines (196 loc) • 8.22 kB
JavaScript
import { defineComponent, reactive, computed, openBlock, createElementBlock, normalizeClass, unref, createElementVNode, renderSlot, createVNode, withCtx, createTextVNode, toDisplayString, createCommentVNode, normalizeStyle, withModifiers, createBlock } from "vue";
import { message, Tooltip, Popconfirm } from "ant-design-vue";
import dayjs from "dayjs";
import "../../icon/src/icon.vue.mjs";
import "../../image-preview/index.mjs";
import { messageName, messageExtraProps, messageExtraEmits, messageOptions } from "./message.mjs";
import { ERROR_IMG, SYSTEM_ICON, IMG_TYPES, DELETE_RECORD_TYPES, SYETEM_FLAG } from "./config.mjs";
import { useViewerApi } from "../../image-preview/src/api/viewerApi.mjs";
import _sfc_main$1 from "../../icon/src/icon.vue2.mjs";
const _hoisted_1 = { class: "message-title" };
const _hoisted_2 = { class: "left" };
const _hoisted_3 = ["src", "onerror", "alt"];
const _hoisted_4 = {
key: 0,
class: "organization-name"
};
const _hoisted_5 = { class: "time" };
const _hoisted_6 = {
key: 0,
class: "message-content"
};
const _hoisted_7 = { key: 0 };
const _hoisted_8 = {
key: 0,
class: "record-file"
};
const _hoisted_9 = ["src"];
const _hoisted_10 = { key: 1 };
const _hoisted_11 = ["href"];
const _hoisted_12 = {
key: 1,
class: "message-content-text"
};
const _hoisted_13 = { key: 2 };
const _hoisted_14 = { class: "message-operates" };
const _hoisted_15 = {
key: 1,
class: "system-info"
};
const _sfc_main = /* @__PURE__ */ defineComponent({
...{ name: messageName },
__name: "message",
props: messageExtraProps,
emits: messageExtraEmits,
setup(__props, { expose: __expose, emit: __emit }) {
const { class: wrapClass } = messageOptions;
const props = __props;
const emit = __emit;
const image = useViewerApi();
const $this = reactive({
errorImg: ERROR_IMG,
systemIcon: SYSTEM_ICON
});
const recordType = computed(() => {
return props.itemData.recordType;
});
const isImage = computed(() => {
const recordFileName = props.itemData.recordFileName || "";
const fileType = recordFileName.split(".").reverse()[0];
return IMG_TYPES.includes(fileType);
});
const isAbledDelete = computed(() => {
return DELETE_RECORD_TYPES.includes(recordType.value) && props.accountID === props.itemData.recordUser;
});
const isSystemType = computed(() => {
const recordType2 = props.itemData.recordType;
return SYETEM_FLAG.includes(recordType2);
});
const Attributes = computed(() => {
const recordFileUrl = props.itemData.recordFileUrl;
return {
url: recordFileUrl,
imgStyle: { width: "100px", height: "100px", borderRadius: "5px" },
imgUrls: [recordFileUrl]
};
});
const ismyMsg = computed(() => {
const { recordUser } = props.itemData;
return recordUser === props.accountID;
});
const initData = () => {
const { recordTime, recordType: recordType2 } = props.itemData;
props.itemData.recordTime = dayjs(recordTime).format("YYYY-MM-DD HH:mm:ss");
if (SYETEM_FLAG.includes(recordType2)) {
props.itemData.recordUserIcon = $this.systemIcon;
}
};
const downloadItem = () => {
emit("download", props.itemData);
};
const deleteItem = async () => {
emit("delete", props.itemData);
};
const previewImage = (url) => {
if (!url) return;
image.preview([url], {
initialViewIndex: 0
});
};
const handleReply = () => {
message.warning("回复功能暂未开发,敬请期待");
};
initData();
__expose({
handleReply
});
return (_ctx, _cache) => {
return openBlock(), createElementBlock("div", {
class: normalizeClass([unref(wrapClass), "cl-message"])
}, [
createElementVNode("div", _hoisted_1, [
createElementVNode("div", _hoisted_2, [
renderSlot(_ctx.$slots, "icon", {}, () => [
createElementVNode("img", {
draggable: "false",
src: isSystemType.value ? $this.systemIcon : _ctx.itemData.recordUserIcon,
onerror: $this.errorImg,
alt: _ctx.itemData.recordUserName
}, null, 8, _hoisted_3)
]),
createVNode(unref(Tooltip), null, {
title: withCtx(() => [
createTextVNode(toDisplayString(isSystemType.value ? "系统动态" : _ctx.itemData.recordUserName + (_ctx.showOrganizationName && _ctx.itemData.organizationName ? "@" + _ctx.itemData.organizationName : "")), 1)
]),
default: withCtx(() => [
createElementVNode("span", null, [
createTextVNode(toDisplayString(isSystemType.value ? "系统动态" : _ctx.itemData.recordUserName), 1),
_ctx.showOrganizationName && _ctx.itemData.organizationName ? (openBlock(), createElementBlock("span", _hoisted_4, "@" + toDisplayString(_ctx.itemData.organizationName), 1)) : createCommentVNode("", true)
])
]),
_: 1
})
]),
createElementVNode("div", _hoisted_5, toDisplayString(_ctx.itemData.recordTime), 1)
]),
!isSystemType.value ? (openBlock(), createElementBlock("div", _hoisted_6, [
_ctx.itemData.recordFileType == "1" ? (openBlock(), createElementBlock("div", _hoisted_7, [
createTextVNode(toDisplayString(_ctx.itemData.recordContent) + " ", 1),
isImage.value ? (openBlock(), createElementBlock("div", _hoisted_8, [
createElementVNode("img", {
src: Attributes.value.url,
style: normalizeStyle(Attributes.value.imgStyle),
alt: "",
onClick: _cache[0] || (_cache[0] = ($event) => previewImage(Attributes.value.url))
}, null, 12, _hoisted_9)
])) : (openBlock(), createElementBlock("div", _hoisted_10, [
createVNode(unref(Tooltip), null, {
title: withCtx(() => [
createTextVNode(toDisplayString(_ctx.itemData.recordFileName), 1)
]),
default: withCtx(() => [
createElementVNode("a", {
href: _ctx.itemData.recordFileUrl,
target: "_blank",
onClick: withModifiers(downloadItem, ["prevent"])
}, toDisplayString(_ctx.itemData.recordFileName), 9, _hoisted_11)
]),
_: 1
})
]))
])) : _ctx.itemData.recordFileType == "2" ? (openBlock(), createElementBlock("div", _hoisted_12, toDisplayString(_ctx.itemData.recordContent), 1)) : (openBlock(), createElementBlock("div", _hoisted_13, toDisplayString(_ctx.itemData.recordContent), 1)),
createElementVNode("div", _hoisted_14, [
isAbledDelete.value && ismyMsg.value ? (openBlock(), createBlock(unref(Popconfirm), {
key: 0,
placement: _ctx.messageOperatesPopPosition,
"ok-text": "确认",
"cancel-text": "取消",
"overlay-class-name": "clmessage-popconfirm",
onConfirm: deleteItem
}, {
icon: withCtx(() => [
createVNode(_sfc_main$1, { type: "question-circle" })
]),
title: withCtx(() => _cache[1] || (_cache[1] = [
createElementVNode("h3", null, "操作确认", -1),
createElementVNode("p", { class: "clmessage-confim-text" }, "确认删除该条动态?", -1)
])),
default: withCtx(() => [
renderSlot(_ctx.$slots, "delete-button", {}, () => [
createVNode(_sfc_main$1, {
class: "item delete-icon",
type: "delete"
})
])
]),
_: 3
}, 8, ["placement"])) : createCommentVNode("", true)
])
])) : (openBlock(), createElementBlock("div", _hoisted_15, toDisplayString(_ctx.itemData.recordContent), 1))
], 2);
};
}
});
export {
_sfc_main as default
};