tinymceee.blade.php 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184
  1. <template id="tinymceee">
  2. <div style="position: relative;">
  3. <div style="text-align: right;position: absolute;z-index: 88;right: 0;top: 4px;">
  4. <el-button size="small" type="primary" @click="openUploadOnlyTextArea()">上传图片</el-button>
  5. </div>
  6. <textarea :id="id_name" style="height:600px" v-model="value"></textarea>
  7. <!--弹框上传图片-->
  8. <el-dialog :visible.sync="uploadShow" width="800px" :before-close="beforeClose" v-if="imgLoading">
  9. <el-tabs v-model="activeName" @tab-click="handleClick">
  10. <el-tab-pane label="选取图片" name="first">
  11. <div class="clearfix con-box">
  12. <div class="scroll-box fl">
  13. <div class="left-group fl" :class="groupList.length > 17?'bor-right':''">
  14. <!-- <p class="TD-gro" v-for="(item,index) in groupList" :class="item.id == groupId && index == groupIndex ? 'text-bg' : ''" @click="handleGroup(item.id,index)">[[item.title]]([[item.source_count]])</p> -->
  15. <div class="TD-gro" v-for="(item,index) in groupList" :class="item.id == groupId && index == groupIndex ? 'text-bg' : ''" @click="handleGroup(item.id,index)">[[item.title]]([[item.source_count]])</div>
  16. </div>
  17. </div>
  18. <div class="right-img" :class="groupList.length <= 17?'bor-left':''">
  19. <div v-if="resourceList.length <= 0" style="text-align:center;margin-top:20px">
  20. 暂没有数据~
  21. </div>
  22. <div v-if="type == 1" class='img-source fl' v-for="(item,index) in resourceList" @click.stop="handChecked('click',item.id,item)">
  23. <img :src="item.url" alt="">
  24. <p>[[item.filename]]</p>
  25. <div class="img-mark" :style="{ display: item.is_choose ? 'block' : '' }">
  26. <el-checkbox v-model="item.is_choose" class="sle-img" @change="handChecked($event,item.id,item)"></el-checkbox>
  27. </div>
  28. </div>
  29. </div>
  30. </div>
  31. <div class="handel clearfix">
  32. <el-popover placement="top" width="300" trigger="click">
  33. <span style="color:#409eff;cursor: pointer;" class="fl" slot="reference">新建分组</span>
  34. <p class="gro-inp">请输入分组名称</p>
  35. <el-input v-model="newGroupName" placeholder="" style="margin-bottom:15px" maxlength="6" show-word-limit></el-input>
  36. <el-button type="primary" class="gro-sure" @click="handAddGroup()" style="margin-left:30px">确定</el-button>
  37. <el-button class="gro-cancel" @click="handCancelGroup()" style="margin-left:50px">取消</el-button>
  38. </el-popover>
  39. <div class="fr">
  40. <el-pagination background @current-change="currentChange" layout="prev, pager, next" :current-page="current_page" :page-size.sync="Number(page_size)" :total="page_total">
  41. </el-pagination>
  42. </div>
  43. </div>
  44. </el-tab-pane>
  45. <el-tab-pane label="提取网络图片" name="second" class="getNet" v-if="type == 1 || type == 3">
  46. <div class="getnetimg" v-if="type == 1">
  47. <el-image class="defaultImg" style="" :src="previewUrl">
  48. <div slot="error" class="image-slot">
  49. <i class="el-icon-picture-outline" style="font-size:40px"></i>
  50. </div>
  51. </el-image>
  52. <div>
  53. <p>输入图片链接</p>
  54. <el-input v-model="imgLink" placeholder="图片链接" style="width:60%;margin:20px"></el-input>
  55. <p>
  56. <el-button style="margin-bottom:20px;width:100px" @click="conversion()">转化</el-button>
  57. </p>
  58. </div>
  59. </div>
  60. </el-tab-pane>
  61. </el-tabs>
  62. <div class="img-hint" v-loading="uploadImgLoading" >
  63. <!-- <el-upload :action="uploadLink" ref="upload" :multiple="multipleTag" accept="image/*" :on-success="handleSucesss" :on-exceed="handleExceed" :before-upload="beforeUpload">
  64. <el-button size="small" type="primary">点击上传</el-button>
  65. </el-upload> -->
  66. <div>
  67. <label for="uploadImgInput" class="uploadImgInput">点击上传</label>
  68. <input type="file" id="uploadImgInput" @change="onChange" accept="image/*" :multiple="multipleTag">
  69. </div>
  70. </div>
  71. <div class="uploading-btn">
  72. <span>已选择</span>
  73. <span v-if="type == 1" style="color:#409eff;">[[selectCount]]/[[resourceTotal]]个图片</span>
  74. <span slot="footer" class="dialog-footer">
  75. <el-button type="primary" @click="sureImg" style="margin-left:20%;width:100px">确 定</el-button>
  76. <el-button @click="beforeClose" style="margin-left:5%;width:100px;">取 消</el-button>
  77. </span>
  78. </div>
  79. </el-dialog>
  80. </div>
  81. </template>
  82. <script>
  83. const upload_url1 = '{!! yzWebFullUrl('upload.uploadV2.upload-vue') !!}';
  84. Vue.component('tinymceee', {
  85. props: ['value'],
  86. delimiters: ['[[', ']]'],
  87. data() {
  88. let self2 = this;
  89. return {
  90. id_name: 'vue-tinymce-' + +new Date() + ((Math.random() * 1000).toFixed(0) + ''),
  91. flag: true,
  92. hasInit: false,
  93. hasChange: false,
  94. uploadImgLoading: false,
  95. // ImgList: [],
  96. //弹框上传图片的路径
  97. uploadImg: "",
  98. uploadImgUrl: "",
  99. netImgUrl: "",
  100. readlyImgList: [],
  101. // chooseImg: "",
  102. // radio1: "", //年
  103. // radio2: "", //月
  104. // activeName2: "first",
  105. //是否显示弹框
  106. // centerDialogVisible: false,
  107. // pageSize: 0,
  108. // current_page: 0,
  109. // total: 0,
  110. // 新增
  111. uploadShow: false,
  112. imgLoading: false,
  113. activeName: 'first',
  114. imgChecked: '',
  115. newGroupName: '',
  116. currentPage3: 0,
  117. netUrl: '',
  118. imgLink: '',
  119. groupList: [],
  120. groupId: '',
  121. groupIndex: '',
  122. imgList: [],
  123. page_size: 12, //
  124. page: 1, //默认请求第一页
  125. current_page: 0,
  126. page_total: 0,
  127. file: {},
  128. resourceTotal: 0,
  129. tabPanStatus: '',
  130. selectArr: [],
  131. netImg: {},
  132. previewUrl: '',
  133. fileList: [],
  134. resourceList: [],
  135. uploadType: '',
  136. uploadLink: '',
  137. selectCount: 0,
  138. videoLink: '',
  139. viewVideoLink: '',
  140. currentPage: 1,
  141. multipleTag: true,
  142. type: 1,
  143. selNum: 'list'
  144. }
  145. },
  146. watch: {
  147. value(val) {
  148. if (!this.hasChange && this.hasInit) {
  149. // tinyMCE.activeEditor.setContent(val);
  150. this.$nextTick(() =>
  151. window.tinymce.get(this.id_name).setContent(val || ''))
  152. }
  153. this.flag = true;
  154. },
  155. // img(){
  156. // if(this.img){
  157. // tinyMCE.activeEditor.insertContent(`<img src="${this.img}" >`)
  158. // }
  159. // }
  160. },
  161. created() {
  162. window.addEventListener('beforeunload', e => {
  163. window.onbeforeunload = null
  164. });
  165. this.getGroupList(this.type)
  166. this.uploadLink = '{!! yzWebFullUrl('upload.uploadV3.upload') !!}'+'&upload_type='+'image'+'&tag_id='+ ''
  167. },
  168. mounted: function() {
  169. var component = this;
  170. tinymce.init({
  171. selector: "#" + component.id_name,
  172. language: "zh_CN",
  173. hasChange: false,
  174. hasInit: false,
  175. //menubar: false,
  176. body_class: 'panel-body ',
  177. object_resizing: false, //调整尺寸
  178. end_container_on_empty_block: true,
  179. powerpaste_word_import: 'merge',
  180. powerpaste_html_import: 'merge',
  181. powerpaste_allow_local_images: true,
  182. code_dialog_height: 450,
  183. code_dialog_width: 1000,
  184. max_height:1000,
  185. advlist_bullet_styles: 'square',
  186. advlist_number_styles: 'default',
  187. imagetools_cors_hosts: ['www.tinymce.com', 'codepen.io'],
  188. fontsize_formats: "8px 10px 12px 14px 16px 18px 20px 22px 24px 28px 30px 36px",
  189. default_link_target: '_blank',
  190. link_title: false,
  191. autosave_ask_before_unload: false,
  192. autosave_interval: '20s',
  193. nonbreaking_force_tab: true, // inserting nonbreaking space &nbsp; need Nonbreaking Space Plugin
  194. plugins: ['autosave advlist anchor autolink autoresize code codesample colorpicker contextmenu directionality emoticons fullscreen hr image imagetools insertdatetime link charmap lists media nonbreaking noneditable pagebreak preview print save searchreplace spellchecker tabfocus table template textcolor textpattern visualblocks visualchars wordcount powerpaste bdmap cimage formatpainter'],
  195. toolbar: ['restoredraft forecolor backcolor searchreplace bold italic underline strikethrough fontsizeselect','alignleft aligncenter alignright outdent indent ltr rtl blockquote undo redo removeformat subscript superscript code codesample', 'hr bullist numlist link image charmap preview anchor pagebreak print insertdatetime media table emoticons fullscreen cimage formatpainter'],
  196. image_advtab: true,
  197. relative_urls: false,
  198. remove_script_host: false,
  199. images_upload_url: upload_url1 + '&upload_type=image',
  200. // image_dimensions:false,
  201. // object_resizing: true,
  202. // paste_webkit_styles: true ,
  203. // inline_styles: true,
  204. // schema: 'html5',
  205. // valid_elements: 'img[]',
  206. // extended_valid_elements: 'img[style|class|src|border|alt|title|hspace|vspace|width|height|align|name|loading]',
  207. file_picker_callback: function(callback, value, meta) {
  208. //文件分类
  209. var filetype = '.pdf, .jpg, .jpeg, .png, .gif, .mp3, .mp4';
  210. //后端接收上传文件的地址
  211. var upurl = upload_url1 +'&upload_type=video';
  212. //为不同插件指定文件类型及后端地址
  213. switch (meta.filetype) {
  214. case 'image':
  215. upurl = upload_url1 +'&upload_type=image';
  216. filetype = '.jpg, .jpeg, .png, .gif';
  217. break;
  218. case 'media':
  219. filetype = '.mp3, .mp4';
  220. break;
  221. case 'file':
  222. default:
  223. }
  224. //模拟出一个input用于添加本地文件
  225. var input = document.createElement('input');
  226. input.setAttribute('type', 'file');
  227. input.setAttribute('accept', filetype);
  228. input.click();
  229. input.onchange = function() {
  230. var file = this.files[0];
  231. const loading = component.$loading({
  232. lock: true,
  233. text: '正在上传',
  234. spinner: 'el-icon-loading',
  235. background: 'rgba(0, 0, 0, 0.7)'
  236. });
  237. var xhr, formData;
  238. // console.log(file, file.name);
  239. xhr = new XMLHttpRequest();
  240. xhr.withCredentials = false;
  241. xhr.open('POST', upurl);
  242. xhr.onload = function() {
  243. var json;
  244. if (xhr.status != 200) {
  245. loading.close();
  246. // failure('HTTP Error: ' + xhr.status);
  247. return;
  248. }
  249. json = JSON.parse(xhr.responseText);
  250. if (!json || typeof json.location != 'string') {
  251. // failure('Invalid JSON: ' + xhr.responseText);
  252. return;
  253. }
  254. loading.close();
  255. callback(encodeURI(json.location), {
  256. title: file.name
  257. });
  258. };
  259. formData = new FormData();
  260. formData.append('file', file, file.name);
  261. xhr.send(formData);
  262. };
  263. },
  264. media_url_resolver: (data, resolve)=> {
  265. try {
  266. let videoUri = encodeURI(data.url);
  267. if(data.url.indexOf('.mp4')>-1) {
  268. // 判断是否mp4 否则用ifarme嵌套
  269. let embedHtml = `<p>
  270. <video src=${ data.url } width="100%" height="auto" style="max-width: 100%;" allowfullscreen="false" controls="controls" controlslist="nodownload">
  271. </video>
  272. </p>`;
  273. resolve({ html: embedHtml });
  274. }else {
  275. let embedHtml = `<p>
  276. <iframe frameborder="0" src=${ data.url } width="100%" height="100%" style="max-width: 100%;">
  277. </iframe>
  278. </p>`;
  279. resolve({ html: embedHtml });
  280. }
  281. } catch (e) {
  282. resolve({ html: "" });
  283. }
  284. },
  285. init_instance_callback: editor => {
  286. if (this.value) {
  287. editor.setContent(this.value)
  288. }
  289. this.hasInit = true
  290. editor.on('NodeChange Change KeyUp SetContent', () => {
  291. this.hasChange = true
  292. this.$emit('input', editor.getContent())
  293. })
  294. },
  295. save_onsavecallback() {
  296. console.log('阻止默认保存')
  297. },
  298. // setup: function(editor) {
  299. // editor.on('input undo redo execCommand blur', function(e) {
  300. // console.log("111111111111111111")
  301. // component.flag=false;
  302. // component.$emit('input', editor.getContent());
  303. // })
  304. // }
  305. });
  306. },
  307. methods: {
  308. setContent(value) {
  309. window.tinymce.get(this.tinymceId).setContent(value)
  310. },
  311. getContent() {
  312. window.tinymce.get(this.tinymceId).getContent()
  313. },
  314. destroyTinymce() {
  315. const tinymce = window.tinymce.get(this.tinymceId)
  316. if (this.fullscreen) {
  317. tinymce.execCommand('mceFullScreen')
  318. }
  319. if (tinymce) {
  320. tinymce.destroy()
  321. }
  322. },
  323. // chooseTheImg(img, img_url) {
  324. // if (img_url) {
  325. // tinyMCE.activeEditor.insertContent(`<img src="${img_url}" data-mce-src="${img_url}">`)
  326. // }
  327. // this.centerDialogVisible = false;
  328. // },
  329. // chooseYear(year) {
  330. // this.currentChange(1);
  331. // },
  332. // chooseMonth(month) {
  333. // this.currentChange(1);
  334. // },
  335. openUploadOnlyTextArea() {
  336. this.uploadShow = true
  337. this.uploadImgUrl = "";
  338. this.netImgUrl = "";
  339. this.centerDialogVisible = true;
  340. this.initData();
  341. this.currentChange(1);
  342. },
  343. sureImg() {
  344. // if (this.uploadImgUrl) {
  345. // tinyMCE.activeEditor.insertContent(`<img src="${this.uploadImgUrl}" >`)
  346. // }
  347. this.fileList.forEach((item, index) => {
  348. tinyMCE.activeEditor.insertContent(`<img src="${item.url}" >`)
  349. })
  350. this.fileList=[];
  351. this.centerDialogVisible = false;
  352. this.uploadShow = false //新增
  353. },
  354. initData() {
  355. this.uploadImgLoading = false;
  356. this.imgLoading = false;
  357. this.ImgList = [];
  358. //弹框上传图片的路径
  359. this.uploadImg = "";
  360. this.uploadImgUrl = "";
  361. this.netImgUrl = "";
  362. this.chooseImg = "";
  363. this.radio1 = "", //年
  364. this.radio2 = "", //月
  365. this.activeName2 = "first";
  366. //是否显示弹框
  367. // this.centerDialogVisible= false;
  368. this.pageSize = 0;
  369. this.current_page = 0;
  370. this.total = 0;
  371. },
  372. // 新增
  373. // 获取分组列表
  374. getGroupList(type) {
  375. this.$http.post('{!! yzWebFullUrl('setting.media.tags') !!}', {
  376. source_type: type
  377. }).then(response => {
  378. if (response.data.result) {
  379. this.groupList = response.data.data
  380. this.imgLoading = true
  381. } else {
  382. this.$message({
  383. message: response.data.msg,
  384. type: 'error'
  385. });
  386. }
  387. }, response => {
  388. this.$message({
  389. message: response.data.msg,
  390. type: 'error'
  391. });
  392. });
  393. },
  394. getMultimediaList(id, pageSize, page, flag) {
  395. let url = ''
  396. if (this.type == 1) { //图片
  397. url = '{!! yzWebFullUrl('upload.uploadV3.getImage') !!}'
  398. this.page_size = 12
  399. }
  400. this.$http.post(url, {
  401. tag_id: id,
  402. pageSize: this.page_size,
  403. page: page
  404. }).then(response => {
  405. if (response.data.result) {
  406. this.page_total = response.data.data.total
  407. // this.page_size = response.data.per_page;
  408. this.current_page = response.data.data.current_page;
  409. this.resourceTotal = response.data.data.total
  410. this.resourceList = response.data.data.data
  411. this.imgLoading = true
  412. if(flag == 'upload') {
  413. // 上传图片之后回显
  414. this.resourceList.forEach((item, index) => {
  415. if(index<this.readlyImgList.length) {
  416. this.handChecked(null,item.id,item)
  417. }
  418. });
  419. $('#uploadImgInput').val('');
  420. this.uploadImgLoading = false;
  421. this.readlyImgList = [];
  422. }else {
  423. this.resourceList.forEach((item, index) => {
  424. item['is_choose'] = 0
  425. });
  426. }
  427. } else {
  428. this.$message({
  429. message: response.data.msg,
  430. type: 'error'
  431. });
  432. }
  433. }, response => {
  434. this.$message({
  435. message: response.data.msg,
  436. type: 'error'
  437. });
  438. });
  439. },
  440. // 添加分组
  441. addGroup(sourceType, groupName) {
  442. this.$http.post('{!! yzWebFullUrl('setting.media.addTag') !!}', {
  443. source_type: sourceType,
  444. title: groupName
  445. }).then(response => {
  446. if (response.data.result) {
  447. this.closePopover()
  448. this.$message({
  449. message: '添加分组成功',
  450. type: 'success'
  451. });
  452. } else {
  453. this.$message({
  454. message: response.data.msg,
  455. type: 'error'
  456. });
  457. }
  458. }, response => {
  459. this.$message({
  460. message: response.data.msg,
  461. type: 'error'
  462. });
  463. });
  464. },
  465. // 提取网络图片
  466. getNetImg(url, tag_id) {
  467. this.$http.post('{!! yzWebFullUrl('upload.uploadV3.fetch') !!}', {
  468. url,
  469. tag_id
  470. }).then(response => {
  471. if (response.data.result) {
  472. this.netImg = response.data.data
  473. console.log(this.netImg, '网络图片')
  474. this.imgLink = '',
  475. this.$message({
  476. message: '图片已提取到未分组',
  477. type: 'success'
  478. });
  479. } else {
  480. this.$message({
  481. message: response.data.msg,
  482. type: 'error'
  483. });
  484. }
  485. }, response => {
  486. this.$message({
  487. message: response.data.msg,
  488. type: 'error'
  489. });
  490. });
  491. },
  492. handleGroup(id, ind) {
  493. this.groupIndex = ind;
  494. this.groupId = id
  495. this.getMultimediaList(id, this.page_size, this.page) //请求每一个分组的资源
  496. this.selectArr = []
  497. if (this.type == 1) {
  498. this.uploadLink = '{!! yzWebFullUrl('upload.uploadV3.upload') !!}'+'&upload_type='+'image'+'&tag_id='+ this.groupId
  499. } else if (this.type == 3) {
  500. this.uploadLink = '{!! yzWebFullUrl('upload.uploadV3.upload') !!}'+'&upload_type='+'video'+'&tag_id='+ this.groupId
  501. } else {
  502. this.uploadLink = '{!! yzWebFullUrl('upload.uploadV3.upload') !!}'+'&upload_type='+'audio'+'&tag_id='+ this.groupId
  503. }
  504. this.selectCount = 0
  505. },
  506. // 新建分组
  507. handAddGroup() {
  508. if (this.newGroupName == '') {
  509. this.$message({
  510. message: '分组名不能为空',
  511. type: 'error'
  512. });
  513. return
  514. }
  515. console.log(this.type);
  516. this.addGroup(this.type, this.newGroupName)
  517. this.newGroupName = ''
  518. // 新建完分组后重新请求分组列表接口
  519. setTimeout(() => {
  520. this.getGroupList(this.type)
  521. }, 800);
  522. this.closePopover()
  523. },
  524. handCancelGroup() {
  525. this.newGroupName = ''
  526. this.closePopover()
  527. },
  528. closePopover() {
  529. if (document.all) {
  530. document.getElementById('tinymceee').click();
  531. } else { // 其它浏览器
  532. var e = document.createEvent('MouseEvents')
  533. e.initEvent('click', true, true)
  534. document.getElementById('tinymceee').dispatchEvent(e)
  535. }
  536. },
  537. // 弹窗的关闭事件
  538. handleClose(done) {
  539. },
  540. handleClick(tab, event) {
  541. this.tabPanStatus = tab.paneName
  542. this.imgLink = ''
  543. this.previewUrl = ''
  544. },
  545. handleSizeChange() {
  546. },
  547. currentChange(val) {
  548. this.currentPage = val
  549. this.getMultimediaList(this.groupId, this.page_size, val)
  550. this.selectCount = 0
  551. },
  552. // 取消按钮
  553. beforeClose() {
  554. this.activeName == 'first'
  555. this.$emit('replace', this.uploadShow);
  556. this.fileList = []
  557. this.resourceList = [] //弹窗退出清空数据,取消勾选状态
  558. this.groupId = ''
  559. this.groupIndex = ''
  560. this.activeName = 'first'
  561. this.uploadShow = false
  562. },
  563. // compare (prop) {
  564. // // 根据prop参数排序
  565. // return function (obj1, obj2) {
  566. // var val1 = obj1[prop];
  567. // var val2 = obj2[prop];
  568. // if (!isNaN(Number(val1)) && !isNaN(Number(val2))) {
  569. // val1 = Number(val1);
  570. // val2 = Number(val2);
  571. // }
  572. // if (val1 < val2) {
  573. // return -1;
  574. // } else if (val1 > val2) {
  575. // return 1;
  576. // } else {
  577. // return 0;
  578. // }
  579. // }
  580. // },
  581. onChange(event) {
  582. this.readlyImgList = event.target.files;
  583. console.log(this.readlyImgList)
  584. let arr = Object.values(this.readlyImgList);
  585. // arr= arr.sort(this.compare("lastModified"))
  586. arr.reverse();
  587. if (arr.length > 5) {
  588. this.$message.error("不能一次上传超过5个文件!");
  589. return
  590. }
  591. this.readlyImgList = arr;
  592. if(this.readlyImgList.length > 0) {
  593. this.uploadImgRequest(this.readlyImgList[0],0)
  594. }
  595. },
  596. uploadImgRequest(file,index) {
  597. // console.log(file,index)
  598. if(index > this.readlyImgList.length-1 || !file) {
  599. this.getMultimediaList(this.groupId, this.page_size, this.page,'upload')
  600. this.getSelect()
  601. this.getGroupList(this.type)
  602. return
  603. }
  604. this.uploadImgLoading = true;
  605. let fd = new FormData();
  606. fd.append("file", file);
  607. $.ajax({
  608. url: this.uploadLink,
  609. method: 'POST',
  610. data: fd,
  611. processData: false,
  612. contentType: false,
  613. }).then((res)=>{
  614. if(res.result == 1) {
  615. this.uploadImgRequest(this.readlyImgList[index+1],index+1)
  616. // res.data.is_choose = true
  617. // this.resourceList.unshift(res.data)
  618. // let arr = this.resourceList.slice(0, this.page_size)
  619. // this.resourceList = arr
  620. this.$message({
  621. message: res.msg,
  622. type: 'success'
  623. });
  624. }else {
  625. console.log('上传失败',file,index)
  626. this.$message.error(res.msg);
  627. this.uploadImgRequest(this.readlyImgList[index+1],index+1)
  628. }
  629. })
  630. },
  631. beforeUpload(file) {
  632. console.log(file,"file",new Date().getTime())
  633. this.resourceList.forEach(item => {
  634. return item.is_choose = false
  635. })
  636. // this.imgLoading = true;
  637. // const isLt2M = file.size / 1024 / 1024 < 4;
  638. // if (!isLt2M) {
  639. // this.$message.error("上传文件大小不能超过 4MB!");
  640. // // this.imgLoading = false;
  641. // }
  642. // return isLt2M;
  643. },
  644. //上传成功的回调
  645. handleSucesss(response, file, fileList) {
  646. if (response.result == 1) {
  647. this.uploadImg = response.data.attachment //存储相对地址,供后期使用
  648. response.data.is_choose = true
  649. this.resourceList.unshift(response.data)
  650. let arr = this.resourceList.slice(0, this.page_size)
  651. this.resourceList = arr
  652. console.log(this.resourceList, '12435435')
  653. this.handChecked(null, response.data.id, response.data)
  654. // this.$refs.upload.clearFiles()
  655. // if(this.resourceList.length >= 8) {
  656. // this.page_total += fileList.length
  657. // }
  658. let url = ''
  659. if (this.type == 1) { //图片
  660. url = '{!! yzWebFullUrl('upload.uploadV3.getImage') !!}'
  661. }
  662. this.$http.post(url, {
  663. tag_id: this.groupId,
  664. pageSize: this.page_size,
  665. page: this.current_page
  666. }).then(response => {
  667. if (response.data.result) {
  668. this.page_total = response.data.data.total
  669. // this.page_size = response.data.per_page;
  670. this.current_page = response.data.data.current_page;
  671. this.resourceTotal = response.data.data.total
  672. // this.resourceList = response.data.data.data
  673. // this.imgLoading = true
  674. // this.resourceList.forEach((item, index) => {
  675. // item['is_choose'] = 0
  676. // });
  677. } else {
  678. this.$message({
  679. message: response.data.msg,
  680. type: 'error'
  681. });
  682. }
  683. }, response => {
  684. this.$message({
  685. message: response.data.msg,
  686. type: 'error'
  687. });
  688. });
  689. this.getSelect()
  690. this.getGroupList(this.type)
  691. this.$message({
  692. message: response.msg,
  693. type: 'success'
  694. });
  695. // this.resourceTotal += fileList.length
  696. } else {
  697. this.$message.error(response.msg);
  698. }
  699. },
  700. // 文件超出个数限制时的钩子
  701. handleExceed(files) {
  702. if (files.length > 5) {
  703. this.$message.error("不能一次上传超过5个文件!");
  704. return
  705. }
  706. },
  707. handChecked(val, id, item) {
  708. if(val == 'click') {
  709. item.is_choose = !item.is_choose
  710. }
  711. if(item.is_choose == undefined) {
  712. item.is_choose = true;
  713. }
  714. this.uploadImgUrl = item.url;
  715. let arr = []
  716. let data = []
  717. let list = []
  718. this.resourceList.forEach(item => {
  719. if (this.selNum == 'one') {
  720. if (item.id !== id) {
  721. item.is_choose = false
  722. }
  723. }
  724. if (item.is_choose == true) {
  725. arr.push(item.id)
  726. list.push(item)
  727. }
  728. })
  729. this.selectArr = arr
  730. this.fileList = list
  731. this.$forceUpdate()
  732. this.getSelect()
  733. },
  734. getSelect() {
  735. let count = 0
  736. this.resourceList.forEach(item => {
  737. if (item.is_choose) {
  738. count++
  739. }
  740. })
  741. this.selectCount = count;
  742. },
  743. //转换网络图片事件
  744. conversion() {
  745. this.previewUrl = this.imgLink;
  746. console.log(this.groupId);
  747. this.getNetImg(this.imgLink, this.groupId)
  748. console.log(this.imgLink);
  749. },
  750. getNetVideo() {
  751. this.viewVideoLink = this.videoLink
  752. this.$emit('videoclik', this.viewVideoLink);
  753. }
  754. },
  755. template: '#tinymceee'
  756. });
  757. </script>
  758. <style scoped>
  759. .ellipsis {
  760. width: 100px;
  761. text-overflow: ellipsis;
  762. white-space: nowrap;
  763. vertical-align: middle;
  764. overflow: hidden
  765. }
  766. /* 上传 */
  767. .aduio-box {
  768. margin-top: 20px
  769. }
  770. .aduio-item {
  771. padding: 10px;
  772. margin: 0 15px 15px 0;
  773. width: 280px;
  774. height: 130px;
  775. border: 1px solid #c8cede;
  776. }
  777. .audio-title {
  778. display: inline-block;
  779. width: 150px;
  780. overflow: hidden;
  781. text-overflow: ellipsis;
  782. white-space: nowrap;
  783. vertical-align: middle
  784. }
  785. .aduio-right {
  786. width: 60px;
  787. height: 60px;
  788. }
  789. .aduio-right {
  790. margin-top: 30px;
  791. text-align: center;
  792. }
  793. .aduio-right img {
  794. width: 40px;
  795. height: 40px;
  796. }
  797. .play-box {
  798. position: relative;
  799. margin: 15px 15px 0 0;
  800. text-align: center;
  801. z-index: 100;
  802. }
  803. .play-box img {
  804. width: 40px;
  805. height: 40px;
  806. }
  807. .uploading-btn {
  808. margin-top: 10px;
  809. /* text-align:center; */
  810. }
  811. .uploading-btn span {
  812. /* text-align:left */
  813. }
  814. .video-box {
  815. margin: 20px 0 30px 0;
  816. width: 100%;
  817. }
  818. .video-box .video-item {
  819. position: relative;
  820. padding: 10px;
  821. margin-right: 15px;
  822. width: 40%;
  823. height: 130px;
  824. border: 1px solid #c8cede;
  825. }
  826. .checked-pos {
  827. position: absolute;
  828. top: 10px;
  829. left: 10px;
  830. }
  831. .vedio-file {
  832. width: 150px;
  833. height: 100%
  834. }
  835. .vedio-file video {
  836. width: 150px;
  837. height: 100%
  838. }
  839. .vedio-right {
  840. text-align: left
  841. }
  842. .vedio-right p {
  843. margin: 20px 0 0 15px;
  844. }
  845. .getNetWork {
  846. margin: 30px 0;
  847. text-align: center
  848. }
  849. .con-box {
  850. position: relative;
  851. }
  852. .left-group {
  853. /* position: relative; */
  854. /* left:-20px; */
  855. /* position: absolute; */
  856. /* height: 500px; */
  857. /* overflow: scroll; */
  858. padding: 10px 0;
  859. left: 0;
  860. top: 0;
  861. width: 180px;
  862. max-width: 150px;
  863. min-width: 110px;
  864. text-overflow: ellipsis;
  865. white-space: nowrap;
  866. vertical-align: middle;
  867. overflow: hidden;
  868. }
  869. .TD-gro {
  870. /* margin: 0; */
  871. padding: 3px 0 3px 0px;
  872. cursor: pointer;
  873. }
  874. .left-group .gro-bg {
  875. background: rgb(41, 186, 156);
  876. color: #fff;
  877. }
  878. .right-img {
  879. /* min-width: 350px; */
  880. margin-left: 150px;
  881. /* width:80%; */
  882. min-height: 475px;
  883. /* border-left:1px solid #c8cede */
  884. }
  885. .handel {
  886. margin-top: 10px;
  887. }
  888. .img-hint {
  889. position: absolute;
  890. width: 200px;
  891. top: 20px;
  892. right: 21px;
  893. margin-bottom: 15px;
  894. height: 40px;
  895. line-height: 40px;
  896. text-align: right;
  897. z-index: 9999;
  898. }
  899. .img-hint>div {
  900. float: right
  901. }
  902. /* 隐藏上传组件的默认样式 */
  903. .img-hint input {
  904. display: none;
  905. }
  906. .img-hint .el-upload-list {
  907. display: none
  908. }
  909. .img-source {
  910. position: relative;
  911. margin: 10px 0 0 10px;
  912. width: 140px;
  913. height: 150px;
  914. }
  915. .img-source img {
  916. width: 100%;
  917. height: 110px;
  918. }
  919. .img-source p {
  920. padding: 0 5px;
  921. width: 100%;
  922. text-overflow: ellipsis;
  923. white-space: nowrap;
  924. vertical-align: middle;
  925. overflow: hidden;
  926. }
  927. .img-source .sle-img {
  928. position: absolute;
  929. /* display:none; */
  930. top: 5px;
  931. left: 5px;
  932. }
  933. .img-source p {
  934. margin-top: 15px;
  935. text-align: center;
  936. }
  937. .img-mark {
  938. position: absolute;
  939. display: none;
  940. width: 100%;
  941. height: 110px;
  942. top: 0px;
  943. left: 0px;
  944. background: rgba(41, 186, 156, 0.3);
  945. border: 1px solid rgb(41, 186, 156);
  946. }
  947. .img-source:hover .img-mark {
  948. display: block
  949. }
  950. .vedio-source,
  951. .audio-source {
  952. position: relative;
  953. margin: 10px 0 0px 23px;
  954. width: 280px;
  955. height: 102px;
  956. border: 1px solid #c8cede;
  957. }
  958. .video-mark {
  959. position: absolute;
  960. padding: 5px;
  961. display: none;
  962. width: 100%;
  963. height: 100%;
  964. top: 0px;
  965. left: 0px;
  966. background: rgba(41, 186, 156, 0.3);
  967. border: 1px solid rgb(41, 186, 156);
  968. }
  969. .vedio-upload {
  970. width: 150px;
  971. height: 100%;
  972. }
  973. .vedio-upload video {
  974. width: 150px;
  975. height: 100%;
  976. vertical-align: top;
  977. }
  978. .vedio-source:hover .video-mark {
  979. display: block
  980. }
  981. .audio-source:hover .video-mark {
  982. display: block
  983. }
  984. .audio-source {}
  985. .defaultImg {
  986. margin-top: 20px;
  987. width: 150px;
  988. height: 150px;
  989. line-height: 150px;
  990. border: 1px solid #c8cede;
  991. text-align: center;
  992. }
  993. .getNet {
  994. text-align: center;
  995. }
  996. .getnetvideo,
  997. .getnetaudio {
  998. min-height: 300px
  999. }
  1000. #multimedia-material .el-tabs__content {
  1001. overflow: initial;
  1002. }
  1003. .video-time {
  1004. position: absolute;
  1005. padding-right: 8px;
  1006. bottom: 10px;
  1007. left: 10px;
  1008. color: #fff;
  1009. width: 50px;
  1010. height: 20px;
  1011. font-size: 12px;
  1012. line-height: 20px;
  1013. border-radius: 5px;
  1014. text-align: right;
  1015. background: rgba(0, 0, 0, 0.5)
  1016. }
  1017. .play-triangle {
  1018. position: absolute;
  1019. top: 3px;
  1020. left: 6px;
  1021. /* padding-left:5px; */
  1022. height: 0;
  1023. width: 0;
  1024. overflow: hidden;
  1025. /* 这里设置overflow, font-size, line-height */
  1026. font-size: 0;
  1027. /*是因为, 虽然宽高度为0, 但在IE6下会具有默认的 */
  1028. line-height: 0;
  1029. /* 字体大小和行高, 导致盒子呈现被撑开的长矩形 */
  1030. border-color: transparent transparent transparent #fff;
  1031. border-style: solid;
  1032. border-width: 7px;
  1033. }
  1034. .bor-left {
  1035. /* border-left: 1px solid #c8cede; */
  1036. }
  1037. .bor-right {
  1038. border-right: 1px solid #c8cede;
  1039. }
  1040. .text-bg {
  1041. background: #29BA9C;
  1042. color: #fff;
  1043. }
  1044. .scroll-box {
  1045. width: 152px;
  1046. height: 475px;
  1047. overflow-y: scroll;
  1048. }
  1049. /*滚动条整体样式*/
  1050. .scroll-box::-webkit-scrollbar {
  1051. width: 2px;
  1052. }
  1053. /*滚动条滑块*/
  1054. .scroll-box::-webkit-scrollbar-thumb {
  1055. border-radius: 30px;
  1056. /* -webkit-box-shadow: inset 0 0 5px rgba(0,0,0,0.2); */
  1057. background: #29BA9C;
  1058. }
  1059. /*滚动条轨道*/
  1060. .scroll-box::-webkit-scrollbar-track {
  1061. -webkit-box-shadow: inset 0 0 1px rgba(0, 0, 0, 0);
  1062. border-radius: 30px;
  1063. background: #ccc;
  1064. }
  1065. .el-tabs__header {
  1066. margin-bottom: 0;
  1067. }
  1068. .el-dialog__body {
  1069. position: relative;
  1070. }
  1071. .image-slot {
  1072. margin-top: 20px;
  1073. }
  1074. .uploadImgInput {
  1075. color: #FFF;
  1076. background-color: #29BA9C;
  1077. border-color: #29BA9C;
  1078. font-size: 12px;
  1079. border-radius: 3px;
  1080. padding: 8px 15px;
  1081. cursor: pointer;
  1082. }
  1083. .tox-dialog__body .tox-dialog__body-nav-item:nth-child(3) {
  1084. display: none;
  1085. }
  1086. </style>