提交 83e93d0b 编写于 作者: 璃白.'s avatar 璃白. 🌻

feat:添加上传视频

上级 d7433ea0
无法预览此类型文件
...@@ -85,7 +85,7 @@ ...@@ -85,7 +85,7 @@
value: value:
"## edswgdfgdfgdfg\n**dfgdfgdfg**\n_ergdfgdfg_\n> ergergdfg\n```\nwefgdfsfdgdf\n```\n- efwefsdfsdf\n\n\nsdgfdfgdfgdfg\n\n\nedrfgdfgdfg\n\n\n\nergergergergerg\nergergergerg\n\n\nedrfgdfgdfg\n\n\n\nergergergergerg\nergergergerg\n\n\nedrfgdfgdfg\n\n\n\nergergergergerg\nergergergerg", "## edswgdfgdfgdfg\n**dfgdfgdfg**\n_ergdfgdfg_\n> ergergdfg\n```\nwefgdfsfdgdf\n```\n- efwefsdfsdf\n\n\nsdgfdfgdfgdfg\n\n\nedrfgdfgdfg\n\n\n\nergergergergerg\nergergergerg\n\n\nedrfgdfgdfg\n\n\n\nergergergergerg\nergergergerg\n\n\nedrfgdfgdfg\n\n\n\nergergergergerg\nergergergerg",
value: value:
"[1](https://img2.baidu.com/it/u=4025475678,645544065&fm=26&fmt=auto&gp=0.jpg)\n[](https://img2.baidu.com/it/u=4025475678,645544065&fm=26&fmt=auto&gp=0.jpg)", "![video](http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4 '1.jpg')\n![video](http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4 '1.jpg')\n![video](http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4 '1.jpg')",
// value: "当前问题已结题,不再开放新的回答。", // value: "当前问题已结题,不再开放新的回答。",
// value: "", // value: "",
disabled: false, disabled: false,
...@@ -143,7 +143,13 @@ ...@@ -143,7 +143,13 @@
onSubmit: function(res) { onSubmit: function(res) {
console.log(res); console.log(res);
}, },
onUpload: function(file, callback) { onUpload: function(file, type, callback) {
console.log(type);
if (type === "video") {
callback("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4");
return;
}
new Promise((res, rej) => { new Promise((res, rej) => {
setTimeout(() => { setTimeout(() => {
res(file); res(file);
...@@ -156,26 +162,27 @@ ...@@ -156,26 +162,27 @@
}; };
}); });
}, },
renderLinks: function(val, callback) { // renderLinks: function(val, callback) {
setTimeout(() => { // setTimeout(() => {
val[0].title = "111111"; // val[0].title = "111111";
val[0].icon = "https://g.csdnimg.cn/static/logo/favicon32.ico"; // val[0].icon = "https://g.csdnimg.cn/static/logo/favicon32.ico";
callback(val); // callback(val);
}, 1000); // }, 1000);
setTimeout(() => { // setTimeout(() => {
val[1].title = "2222222"; // val[1].title = "2222222";
val[1].icon = "https://g.csdnimg.cn/static/logo/favicon32.ico"; // val[1].icon = "https://g.csdnimg.cn/static/logo/favicon32.ico";
callback(val); // callback(val);
}, 2000); // }, 2000);
setTimeout(() => { // setTimeout(() => {
val[1].title = "333333333"; // val[1].title = "333333333";
val[1].icon = "https://img2.baidu.com/it/u=4025475678,645544065&fm=26&fmt=auto&gp=0.jpg)\n[](https://img2.baidu.com/it/u=4025475678,645544065&fm=26&fmt=auto&gp=0.jpg"; // val[1].icon =
// "https://img2.baidu.com/it/u=4025475678,645544065&fm=26&fmt=auto&gp=0.jpg)\n[](https://img2.baidu.com/it/u=4025475678,645544065&fm=26&fmt=auto&gp=0.jpg";
callback(val); // callback(val);
}, 3000); // }, 3000);
}, // },
queryUserList: function(val, callback) { queryUserList: function(val, callback) {
const list = [ const list = [
{ {
......
此差异已折叠。
...@@ -224,14 +224,28 @@ export default { ...@@ -224,14 +224,28 @@ export default {
}, },
uploadFileCallBack() { uploadFileCallBack() {
const _this = this; const _this = this;
return function({ url, file: { name } }) { return function({ url, file: { name, size } }) {
// url = "http://www.baidu.com";
const originalText = _this.text; const originalText = _this.text;
const selectionInfo = _this.selectionInfo; const selectionInfo = _this.selectionInfo;
const newText = formatText( const newText = formatText(
originalText, originalText,
selectionInfo, selectionInfo,
"\n![file](", "\n![file](",
`${url} '${name} ${size}')\n`
);
_this.text = newText;
_this.$refs.mdUploadFile.value = "";
};
},
uploadVideoCallBack() {
const _this = this;
return function({ url, file: { name } }) {
const originalText = _this.text;
const selectionInfo = _this.selectionInfo;
const newText = formatText(
originalText,
selectionInfo,
"\n![video](",
`${url} '${name}')\n` `${url} '${name}')\n`
); );
_this.text = newText; _this.text = newText;
...@@ -361,9 +375,12 @@ export default { ...@@ -361,9 +375,12 @@ export default {
if (!val.length) return; if (!val.length) return;
this.$emit("upload", { this.$emit("upload", {
val: val[0], val: val[0],
type: uploadType,
callback: callback:
uploadType === "img" uploadType === "img"
? this.uploadImgCallBack ? this.uploadImgCallBack
: uploadType === "video"
? this.uploadVideoCallBack
: this.uploadFileCallBack : this.uploadFileCallBack
}); });
this.fileList = []; this.fileList = [];
......
import marked from "marked"; import marked from "marked";
import videojs from "video.js";
import "video.js/dist/video-js.min.css";
// 获取选中文本信息 // 获取选中文本信息
export function getSelectionInfo(selectorId) { export function getSelectionInfo(selectorId) {
...@@ -412,3 +414,55 @@ export function preventDefault(id) { ...@@ -412,3 +414,55 @@ export function preventDefault(id) {
}, 0); }, 0);
return; return;
} }
export async function renderVideo(id, html) {
const virtualDom = document.createElement("div");
virtualDom.innerHTML = html;
document.body.appendChild(virtualDom);
const videoList = Array.from(virtualDom.getElementsByTagName("video"));
const newHtml = await new Promise((resolve, rej) => {
videoList.forEach(item => {
console.log(item);
item.setAttribute("controls", "controls");
});
setTimeout(() => {
const newHtml = virtualDom.innerHTML;
resolve(newHtml);
// document.body.removeChild(virtualDom);
}, 5000);
});
console.log(newHtml);
// if (newHtml) {
return newHtml;
// }
}
// 获取方法参数名
export function getParameterName(fn) {
if (typeof fn !== "object" && typeof fn !== "function") return;
const COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm;
const DEFAULT_PARAMS = /=[^,)]+/gm;
const FAT_ARROWS = /=>.*$/gm;
let code = fn.prototype ? fn.prototype.constructor.toString() : fn.toString();
code = code
.replace(COMMENTS, "")
.replace(FAT_ARROWS, "")
.replace(DEFAULT_PARAMS, "");
let result = code
.slice(code.indexOf("(") + 1, code.indexOf(")"))
.match(/([^\s,]+)/g);
return result === null ? [] : result;
}
export function getfilesize(size) {
if (!size || isNaN(size)) return size;
var num = 1024.0; //byte
if (size < num) return size + "B";
if (size < Math.pow(num, 2)) return (size / num).toFixed(2) + "K"; //kb
if (size < Math.pow(num, 3))
return (size / Math.pow(num, 2)).toFixed(2) + "M"; //M
if (size < Math.pow(num, 4))
return (size / Math.pow(num, 3)).toFixed(2) + "G"; //G
return (size / Math.pow(num, 4)).toFixed(2) + "T"; //T
}
...@@ -118,3 +118,7 @@ ...@@ -118,3 +118,7 @@
.icon-xiazai:before { .icon-xiazai:before {
content: "\e6be"; content: "\e6be";
} }
.icon-shipin:before {
content: "\e63c";
}
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
</div> </div>
</template> </template>
<script> <script>
import marked from "marked";
export default { export default {
data() { data() {
return {}; return {};
...@@ -32,7 +31,7 @@ export default { ...@@ -32,7 +31,7 @@ export default {
default: 0 default: 0
}, },
html: { html: {
type: String, type: [String, Promise],
default: "" default: ""
}, },
fullScreen: { fullScreen: {
......
...@@ -71,7 +71,7 @@ export default { ...@@ -71,7 +71,7 @@ export default {
default: "" default: ""
}, },
html: { html: {
type: String, type: [String, Promise],
default: "" default: ""
}, },
htmlMinHeight: { htmlMinHeight: {
...@@ -298,7 +298,7 @@ export default { ...@@ -298,7 +298,7 @@ export default {
this.emitText(); this.emitText();
}, },
blur() { blur() {
this.renderUserTags() this.renderUserTags();
this.setFocus(false); this.setFocus(false);
}, },
createHideEl(type) { createHideEl(type) {
......
...@@ -2,13 +2,15 @@ import { ...@@ -2,13 +2,15 @@ import {
getFilteredTags, getFilteredTags,
getLinkTags, getLinkTags,
addLanguageClass, addLanguageClass,
addLinkTarget addLinkTarget,
renderVideo,
getfilesize
} from "@/assets/js/utils"; } from "@/assets/js/utils";
import marked from "marked"; import marked from "marked";
import DOMPurify from "dompurify"; import DOMPurify from "dompurify";
export default { export default {
methods: { methods: {
transferMarkdown(val) { async transferMarkdown(val) {
this.rerender(); this.rerender();
marked.setOptions({ marked.setOptions({
breaks: true, breaks: true,
...@@ -37,9 +39,10 @@ export default { ...@@ -37,9 +39,10 @@ export default {
// 链接转换为卡片 // 链接转换为卡片
const { vDom, links } = getLinkTags(this.id, cleanHtml); const { vDom, links } = getLinkTags(this.id, cleanHtml);
const { callUserList, userHtml } = addLinkTarget(cleanHtml); const { callUserList, userHtml } = addLinkTarget(cleanHtml);
const videoHtml = await renderVideo(this.id, userHtml);
this.$emit("callUserList", callUserList); this.$emit("callUserList", callUserList);
this.$emit("getFilteredTags", filteredTags); this.$emit("getFilteredTags", filteredTags);
this.$emit("update:html", userHtml); this.$emit("update:html", videoHtml);
if (links.length) this.$emit("renderLinksHtml", { vDom, links }); if (links.length) this.$emit("renderLinksHtml", { vDom, links });
}, },
rerender() { rerender() {
...@@ -49,14 +52,19 @@ export default { ...@@ -49,14 +52,19 @@ export default {
if (href === null) { if (href === null) {
return text; return text;
} }
const size = title.split(" ").pop();
const name = title
.split(" ")
.slice(0, -1)
.join(" ");
// ![file](...)渲染文件,只可以下载 // ![file](...)渲染文件,只可以下载
if (text === "file") { if (text === "file") {
return `<div id="md_file_card" class="md_file_card"> return `<div id="md_file_card" class="md_file_card">
<div class="md_flex_card"> <div class="md_flex_card">
<span class="md_file_img icon iconfont icon-doc"></span> <span class="md_file_img icon iconfont icon-doc"></span>
<span class="flex-1"> <span class="flex-1">
<span class="md_file_title">${title}</span> <span class="md_file_title">${name}</span>
<span class="md_file_desc">16.6KB</span> <span class="md_file_desc">${getfilesize(size)}</span>
</span> </span>
<span class="md_file_controls"> <span class="md_file_controls">
<a href="${href}" type="file" download class="md_file_download icon iconfont icon-xiazai"></a> <a href="${href}" type="file" download class="md_file_download icon iconfont icon-xiazai"></a>
...@@ -64,6 +72,15 @@ export default { ...@@ -64,6 +72,15 @@ export default {
</div> </div>
</div>`; </div>`;
} }
if (text === "video") {
return `<video
class="video-js"
controls
preload="auto"
data-setup='{}'>
<source src="${href}" type="video/mp4"></source>
</video>`;
}
// ![img](...)渲染图片 // ![img](...)渲染图片
let out = '<img src="' + href + '" alt="' + text + '"'; let out = '<img src="' + href + '" alt="' + text + '"';
if (title) { if (title) {
......
...@@ -164,6 +164,12 @@ export default { ...@@ -164,6 +164,12 @@ export default {
case "file": case "file":
this.$emit("upload", "file"); this.$emit("upload", "file");
break; break;
case "video":
this.$emit("upload", "video");
break;
case "file":
this.$emit("upload", "file");
break;
case "fullScreen": case "fullScreen":
this.$emit("setFullScreen", true); this.$emit("setFullScreen", true);
break; break;
...@@ -218,7 +224,8 @@ export default { ...@@ -218,7 +224,8 @@ export default {
&.icon-lianjie { &.icon-lianjie {
font-size: 16px; font-size: 16px;
} }
&.icon-help { &.icon-help,
&.icon-wenjian {
font-size: 19px; font-size: 19px;
} }
} }
......
...@@ -237,6 +237,13 @@ export default { ...@@ -237,6 +237,13 @@ export default {
startStr: "", startStr: "",
endStr: "" endStr: ""
}, },
{
name: "video",
icon: "shipin",
tip: "上传视频",
startStr: "",
endStr: ""
},
{ {
name: "task", name: "task",
icon: "renwu", icon: "renwu",
......
...@@ -2,7 +2,12 @@ import Vue from "vue"; ...@@ -2,7 +2,12 @@ import Vue from "vue";
import App from "./App"; import App from "./App";
import Vtip from "vtip"; import Vtip from "vtip";
import "vtip/lib/index.min.css"; import "vtip/lib/index.min.css";
import { initStyle, setzIndex, isNotEmpty } from "@/assets/js/utils"; import {
initStyle,
setzIndex,
isNotEmpty,
getParameterName
} from "@/assets/js/utils";
import "@/assets/style/global.less"; import "@/assets/style/global.less";
Vue.use(Vtip.directive); Vue.use(Vtip.directive);
...@@ -105,15 +110,23 @@ function initMdEditor(obj) { ...@@ -105,15 +110,23 @@ function initMdEditor(obj) {
submit(val) { submit(val) {
onSubmit(val); onSubmit(val);
}, },
upload({ val, callback }) { upload({ val, type, callback }) {
console.log(val); const params = getParameterName(onUpload);
if (!params.includes("type")) {
onUpload(val, function(res) { onUpload(val, function(res) {
callback({ callback({
url: res, url: res,
file: val file: val
});
}); });
}); } else {
onUpload(val, type, function(res) {
callback({
url: res,
file: val
});
});
}
}, },
renderLinks({ links, callback }) { renderLinks({ links, callback }) {
if (!renderLinks) return callback(links); if (!renderLinks) return callback(links);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册