contentOperation.vue 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046
  1. <template>
  2. <div class="m-container">
  3. <h2>
  4. <el-page-header @back="onCancel"
  5. :content="(pageType == 'create' ? '添加' : '修改') + typeChange(type)"></el-page-header>
  6. </h2>
  7. <div class="m-core">
  8. <el-form :model="form"
  9. :rules="rules"
  10. ref="form"
  11. label-width="120px"
  12. style="width: 100%">
  13. <el-form-item label="标题"
  14. prop="title">
  15. <el-input v-model.trim="form.title"></el-input>
  16. </el-form-item>
  17. <el-form-item label="排序值">
  18. <el-input v-model.trim="form.order"></el-input>
  19. </el-form-item>
  20. <!-- <el-form-item label="适用范围"
  21. prop="tenantId">
  22. <el-select v-model="form.tenantId" style="width: 400px !important">
  23. <el-option label="对内"
  24. value="1"></el-option>
  25. <el-option label="对外"
  26. value="2"></el-option>
  27. </el-select>
  28. </el-form-item> -->
  29. <el-form-item label="所属分部"
  30. prop="organIdList">
  31. <!-- <el-select v-model="form.organIdList" placeholder="请选择所属分部" style="width: 400px !important">
  32. <el-option
  33. v-for="(item, index) in selects.branchs"
  34. :key="index"
  35. :label="item.name"
  36. :value="item.id"
  37. ></el-option>
  38. </el-select> -->
  39. <select-all v-model.trim="form.organIdList"
  40. style="width: 400px !important"
  41. filterable
  42. placeholder="请选择分部"
  43. multiple
  44. clearable>
  45. <el-option v-for="(item,index) in selects.branchs"
  46. :key="index"
  47. :label="item.name"
  48. :value="item.id"></el-option>
  49. </select-all>
  50. </el-form-item>
  51. <el-form-item
  52. prop="subjectIdList" v-if="type == 7"
  53. label="所属声部"
  54. :rules="[{required: true, message:'请选择声部', trigger: 'blur, change'}]">
  55. <select-all v-model="form.subjectIdList" clearable filterable multiple placeholder="请选择声部" style="width: 400px !important">
  56. <el-option v-for="item in selects.subjects" :value="item.id" :label="item.name" :key="item.id"></el-option>
  57. </select-all>
  58. </el-form-item>
  59. <!-- banner图 && app按钮管理,才需要添加版本号 -->
  60. <el-form-item label="版本号"
  61. v-if="type == 3 || type == 6 || type == 8">
  62. <el-input v-model="form.memo"></el-input>
  63. </el-form-item>
  64. <!-- -->
  65. <!-- <el-form-item v-if="type == 3 || type == 6 || type == 5 || type == 8" label="链接地址">
  66. <el-input v-model.trim="form.linkUrl"></el-input>
  67. </el-form-item> -->
  68. <el-form-item label="链接地址"
  69. prop="linkUrl"
  70. :rules='[{ required: type == 3 || type == 6 || type == 5 || type == 8 ? false : true, message: "请输入链接地址", trigger: "blur" }]'>
  71. <el-input v-model.trim="form.linkUrl"></el-input>
  72. </el-form-item>
  73. <!-- 闪页, BANNER, 广告页 -->
  74. <el-form-item label="上架时间" v-if="type == 5 || type == 8 || type == 3" prop="actionTime">
  75. <el-date-picker style="width:400px;"
  76. v-model="form.actionTime"
  77. :clearable="true"
  78. type="datetimerange"
  79. :default-time="['00:00:00', '23:59:59']"
  80. range-separator="至"
  81. :picker-options="{ firstDayOfWeek: 1 }"
  82. start-placeholder="上架开始日期"
  83. end-placeholder="上架结束日期">
  84. </el-date-picker>
  85. </el-form-item>
  86. <!-- 广告管理才有类型 -->
  87. <el-form-item label="广告类型"
  88. v-if="type == 8">
  89. <el-select v-model="uploadType" style="width: 400px !important"
  90. :disabled="pageType != 'create'">
  91. <el-option label="图片"
  92. :value="1"></el-option>
  93. <el-option label="视频"
  94. :value="2"></el-option>
  95. </el-select>
  96. </el-form-item>
  97. <el-form-item v-if="uploadType == 2 && type == 8"
  98. key="coverImage"
  99. label="广告视频"
  100. prop="coverImage">
  101. <div @click="addAdvVideo"
  102. style="display: inline-block;">
  103. <video class="avatar"
  104. v-if="form.coverImage"
  105. type="video/mp4"
  106. preload="auto"
  107. :poster="form.videoCoverImage"
  108. :src="form.coverImage"></video>
  109. <i v-else
  110. class="el-icon-plus avatar-uploader-icon"></i>
  111. </div>
  112. <p style="color: red">上传视频尺寸建议:1242px * 2208px;</p>
  113. </el-form-item>
  114. <el-form-item v-else
  115. key="coverImage"
  116. :label="type == 8 ? '广告图' : '封面图'"
  117. prop="coverImage">
  118. <el-upload class="avatar-uploader"
  119. action="/api-web/uploadFile"
  120. :headers="headers"
  121. :show-file-list="false"
  122. accept=".jpg, .jpeg, .png, .gif"
  123. :on-success="handleAvatarSuccess"
  124. :before-upload="beforeAvatarUpload">
  125. <!-- 判断是图片还是视频 -->
  126. <img v-if="form.coverImage"
  127. :src="form.coverImage"
  128. class="avatar" />
  129. <i v-else
  130. class="el-icon-plus avatar-uploader-icon"></i>
  131. </el-upload>
  132. <p class="imageSize"
  133. v-if="imageSize">上传图片尺寸为:{{ imageSize }}</p>
  134. </el-form-item>
  135. <!-- 广告管理才有时长 -->
  136. <el-form-item label="显示时长(秒)"
  137. prop="attribute1"
  138. :rules="[{required: true, validator: validNum, trigger: 'blur'}]"
  139. v-if="type == 8">
  140. <el-input type="number"
  141. v-model.number="form.attribute1"></el-input>
  142. <p style="color: red">建议时长不超过5秒</p>
  143. </el-form-item>
  144. <!-- 知识库管理才会有类型 -->
  145. <el-form-item v-if="type == 7 || type == 2"
  146. :label="type == 7 ? '知识类别' : '资讯类别'"
  147. prop="subType"
  148. :rules="[{ required: true, message: (type == 7 ? '请选择知识类别' : '请选择资讯类别'), trigger: 'change' }]">
  149. <el-select v-model="form.subType" style="width: 400px !important">
  150. <el-option v-for="item in typeList" :key="item.id" :label="item.name" :value="item.id"></el-option>
  151. <!-- <el-option label="演奏小技巧"
  152. :value="1"></el-option>
  153. <el-option label="乐理基础"
  154. :value="2"></el-option>
  155. <el-option label="乐器保养"
  156. :value="3"></el-option>
  157. <el-option label="乐曲演奏展示"
  158. :value="4"></el-option> -->
  159. </el-select>
  160. </el-form-item>
  161. <!-- 闪页管理 BANNER管理 APP按钮管理 广告管理 -->
  162. <el-form-item label="内容"
  163. v-show="type != 8 && type != 5 && type != 3 && type != 6"
  164. prop="content"
  165. :rules="[{ required: type != 8 && type != 5 && type != 3 && type != 6 ? true : false, message: '请编辑内容', trigger: 'blur' }]">
  166. <quill-editor class="ql-editor"
  167. v-model="form.content"
  168. ref="myQuillEditor"
  169. :options="editorOption"
  170. @change="onEditorChange($event)"></quill-editor>
  171. <el-upload class="ivu-upload"
  172. :show-upload-list="false"
  173. :headers="headers"
  174. :on-success="handleSuccess"
  175. accept=".jpg, .jpeg, .png, .gif"
  176. :max-size="2048"
  177. multiple
  178. action="/api-web/uploadFile">
  179. <Button icon="ios-cloud-upload-outline"></Button>
  180. </el-upload>
  181. </el-form-item>
  182. <el-form-item>
  183. <el-button @click="onSubmit('form')"
  184. type="primary">立即{{ pageType == "create" ? '创建' : '修改' }}</el-button>
  185. <el-button @click="onReSet('form')">重置</el-button>
  186. <el-button @click="onLook"
  187. v-if="type != 8 && type != 5 && type != 3 && type != 6">预览</el-button>
  188. </el-form-item>
  189. </el-form>
  190. </div>
  191. <el-dialog title="插入视频"
  192. width="500px"
  193. @close="onDialogClose('diologForm')"
  194. :visible.sync="dialogFormVisible">
  195. <el-form :model="dialogForm"
  196. ref="diologForm"
  197. :rules="dialogFormRules">
  198. <el-form-item label="封面图地址"
  199. prop="poster"
  200. :rules="[{required: uploadType == 2 ? true : false, message: '请上传封面图', trigger: 'blur'}]"
  201. label-width="120px">
  202. <el-upload class="avatar-uploader"
  203. style="line-height: 0;display: inline-block"
  204. action="/api-web/uploadFile"
  205. :headers="headers"
  206. :show-file-list="false"
  207. v-loading="uploadImgLoading"
  208. accept=".jpg, .jpeg, .png, .gif"
  209. :on-success="handleImgSuccess"
  210. :on-error="handleUploadImgError"
  211. :before-upload="beforeImgUpload">
  212. <img v-if="dialogForm.poster"
  213. :src="dialogForm.poster"
  214. class="avatar" />
  215. <i v-else
  216. class="el-icon-plus avatar-uploader-icon"></i>
  217. </el-upload>
  218. </el-form-item>
  219. <el-form-item label="视频类型"
  220. label-width="120px">
  221. <el-radio-group v-model="formRadio">
  222. <el-radio :label="1">外部链接</el-radio>
  223. <el-radio :label="2">上传</el-radio>
  224. </el-radio-group>
  225. </el-form-item>
  226. <el-form-item v-if="formRadio == 1"
  227. label="视频地址"
  228. label-width="120px"
  229. prop="url">
  230. <el-input v-model="dialogForm.url"
  231. style="width: 100%;"
  232. autocomplete="off"></el-input>
  233. </el-form-item>
  234. <el-form-item v-if="formRadio == 2"
  235. label="上传视频"
  236. label-width="120px"
  237. prop="videoUrl">
  238. <el-upload class="upload-demo"
  239. style="display: inline-block"
  240. v-loading="uploadLoading"
  241. action="/api-web/uploadFile"
  242. :before-upload="beforeUpload"
  243. :on-success="handleUploadSuccess"
  244. :on-error="handleUploadError"
  245. :show-file-list="false"
  246. accept=".mp4"
  247. :file-list="fileList"
  248. :on-exceed="handleExceed">
  249. <video style="width: 120px; height: 120px"
  250. v-if="dialogForm.videoUrl"
  251. type="video/mp4"
  252. preload="auto"
  253. :src="dialogForm.videoUrl"></video>
  254. <i v-else
  255. class="el-icon-plus avatar-uploader-icon"></i>
  256. </el-upload>
  257. <p class="imageSize">
  258. <!-- 广告管理 & 广告类型为 视频 -->
  259. <span v-if="uploadType == 2 && type == 8">上传视频尺寸建议:1242px * 2208px;</span><br />
  260. 只能上传mp4文件, 且不超过100M
  261. </p>
  262. </el-form-item>
  263. </el-form>
  264. <div slot="footer"
  265. class="dialog-footer">
  266. <el-button @click="dialogFormVisible = false">取 消</el-button>
  267. <el-button type="primary"
  268. @click="onVideoComfirm('diologForm')">确 定</el-button>
  269. </div>
  270. </el-dialog>
  271. <el-dialog width="375px" title="预览"
  272. :visible.sync="lookVisible">
  273. <div class="sd-container">
  274. <h2>{{ dataInfo.title }}</h2>
  275. <div class="titleInfo">
  276. <!-- <p>{{ dataInfo.tenantId == 2 ? '' : '大雅乐盟' }}</p> -->
  277. <p>{{ typeCheck(dataInfo.type) }}</p>
  278. <p>{{ dataInfo.updateTime }}</p>
  279. </div>
  280. <div class="msgWrap quill-editor ql-editor"
  281. v-html="dataInfo.content"></div>
  282. </div>
  283. </el-dialog>
  284. </div>
  285. </template>
  286. <script>
  287. import { newsQueryId, newsAdd, newsUpdate, newsTypeList } from "@/api/contentManager";
  288. import store from "@/store";
  289. import { getToken } from "@/utils/auth";
  290. import { vaildStudentUrl } from "@/utils/validate";
  291. // import E from 'wangeditor'
  292. // require styles
  293. import "quill/dist/quill.core.css";
  294. import "quill/dist/quill.snow.css";
  295. import "quill/dist/quill.bubble.css";
  296. import Quill from "quill";
  297. import { quillEditor } from "vue-quill-editor";
  298. // 工具栏配置
  299. const toolbarOptions = [
  300. ["bold", "italic", "underline", "strike"], // 加粗 斜体 下划线 删除线
  301. ["blockquote", "code-block"], // 引用 代码块
  302. [{ header: 1 }, { header: 2 }], // 1、2 级标题
  303. [{ list: "ordered" }, { list: "bullet" }], // 有序、无序列表
  304. [{ script: "sub" }, { script: "super" }], // 上标/下标
  305. [{ indent: "-1" }, { indent: "+1" }], // 缩进
  306. // [{'direction': 'rtl'}], // 文本方向
  307. [{ size: ["small", false, "large", "huge"] }], // 字体大小
  308. [{ header: [1, 2, 3, 4, 5, 6, false] }], // 标题
  309. [{ color: [] }, { background: [] }], // 字体颜色、字体背景颜色
  310. [{ font: [] }], // 字体种类
  311. [{ align: [] }], // 对齐方式
  312. ["clean"], // 清除文本格式
  313. ["image", "video"] // 链接、图片、视频
  314. // ["link", "image", "video"] // 链接、图片、视频
  315. ];
  316. // 标题
  317. const titleConfig = {
  318. "ql-bold": "加粗",
  319. "ql-color": "颜色",
  320. "ql-font": "字体",
  321. "ql-code": "插入代码",
  322. "ql-italic": "斜体",
  323. // 'ql-link': '添加链接',
  324. "ql-background": "背景颜色",
  325. "ql-size": "字体大小",
  326. "ql-strike": "删除线",
  327. "ql-script": "上标/下标",
  328. "ql-underline": "下划线",
  329. "ql-blockquote": "引用",
  330. "ql-header": "标题",
  331. "ql-indent": "缩进",
  332. "ql-list": "列表",
  333. "ql-align": "文本对齐",
  334. "ql-direction": "文本方向",
  335. "ql-code-block": "代码块",
  336. "ql-formula": "公式",
  337. "ql-image": "图片",
  338. "ql-video": "视频",
  339. "ql-clean": "清除字体样式",
  340. "ql-upload": "文件"
  341. };
  342. let validNum = (rule, value, callback) => {
  343. if (typeof value == 'string' || value == null) {
  344. callback(new Error('请输入显示时长'))
  345. } else if (value < 0) {
  346. callback(new Error('输入显示时长必须大于0'))
  347. } else {
  348. callback()
  349. }
  350. }
  351. // 这里引入修改过的video模块并注册
  352. import Video from "../quill/video.js";
  353. import dayjs from 'dayjs'
  354. Quill.register(Video, true);
  355. export default {
  356. name: "contentOperation",
  357. components: {
  358. quillEditor
  359. },
  360. data () {
  361. let that = this;
  362. const query = this.$route.query
  363. let url = ''
  364. // let url = query.type == 7 ? vaildStudentUrl() + "/#/knowledge" : vaildStudentUrl() + "/#/specialdetail"
  365. // console.log(query.type)
  366. if (query.type == 7) {
  367. url = vaildStudentUrl() + "/#/knowledge"
  368. } else if (query.type == 8 || query.type == 5) {
  369. url = ''
  370. } else {
  371. url = vaildStudentUrl() + "/#/specialdetail"
  372. }
  373. return {
  374. validNum: validNum,
  375. uploadType: 1, // 上传类型
  376. uploadStatus: false,
  377. categoryList: [],
  378. type: query.type,
  379. pageType: query.pageType,
  380. organId: null,
  381. headers: {
  382. Authorization: getToken()
  383. },
  384. content: null,
  385. dialogFormVisible: false,
  386. formRadio: 1,
  387. lookVisible: false,
  388. dataInfo: {
  389. title: '',
  390. type: query.type,
  391. updateTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
  392. content: null
  393. },
  394. editorIndex: 0, // 光标位置
  395. editorOption: {
  396. placeholder: "请输入内容",
  397. modules: {
  398. toolbar: {
  399. container: toolbarOptions,
  400. handlers: {
  401. image: function (value) {
  402. if (value) {
  403. // 调用iview图片上传
  404. document.querySelector(".ivu-upload .el-upload").click();
  405. } else {
  406. this.quill.format("image", false);
  407. }
  408. },
  409. video: function (value) {
  410. if (value) {
  411. that.dialogFormVisible = true;
  412. let editor = that.$refs.myQuillEditor.quill;
  413. that.editorIndex = editor.getSelection().index;
  414. } else {
  415. this.quill.format("image", false);
  416. }
  417. }
  418. }
  419. }
  420. }
  421. },
  422. dialogForm: {
  423. poster: null,
  424. url: null,
  425. videoUrl: null
  426. },
  427. uploadLoading: false,
  428. uploadImgLoading: false,
  429. fileList: [],
  430. dialogFormRules: {
  431. url: [{ required: true, message: "请输入视频地址", trigger: "blur" }],
  432. videoUrl: [{ required: true, message: "请上传视频", trigger: 'blur' }]
  433. },
  434. form: {
  435. title: null,
  436. order: null,
  437. // tenantId: null,
  438. coverImage: null,
  439. videoCoverImage: null,
  440. attribute1: null, // 时长
  441. linkUrl: url,
  442. subjectIdList: null, // 声部编号
  443. type: query.type,
  444. status: 1,
  445. content: null,
  446. subType: null,
  447. actionTime: null,
  448. organIdList: null,
  449. },
  450. rules: {
  451. title: [
  452. { required: true, message: "请输入标题", trigger: "blur" },
  453. { min: 2, max: 30, message: "长度在 2 到 30 个字符", trigger: "blur" }
  454. ],
  455. coverImage: [
  456. { required: true, message: '请选择封面图或广告视频', trigger: "blur" }
  457. ],
  458. organIdList: [{ required: true, message: "请选择分部", trigger: "change" }],
  459. },
  460. imageSize: null,
  461. typeList: [], //子分类列表
  462. };
  463. },
  464. created () { },
  465. mounted () {
  466. const query = this.$route.query
  467. if (query.pageType == "create") {
  468. let url = ''
  469. if (query.type == 7) {
  470. url = vaildStudentUrl() + "/#/knowledge"
  471. } else if (query.type == 8 || query.type == 5) {
  472. url = ''
  473. } else {
  474. url = vaildStudentUrl() + "/#/specialdetail"
  475. }
  476. this.form = {
  477. title: null,
  478. order: null,
  479. coverImage: null,
  480. videoCoverImage: null,
  481. attribute1: null,
  482. linkUrl: url,
  483. type: query.type,
  484. subjectIdList: null,
  485. status: 1,
  486. content: null,
  487. // tenantId: null,
  488. organIdList: null,
  489. subType: null,
  490. actionTime: null
  491. };
  492. this.$refs["form"].clearValidate();
  493. this.dialogForm = {
  494. poster: null,
  495. url: null,
  496. videoUrl: null
  497. }
  498. this.fileList = []
  499. }
  500. this.type = query.type;
  501. this.pageType = query.pageType;
  502. // 获取声部
  503. this.$store.dispatch('setSubjects')
  504. this.$store.dispatch("setBranchs");
  505. this.init();
  506. },
  507. methods: {
  508. init () {
  509. this.getList();
  510. this.addQuillTitle();
  511. const query = this.$route.query
  512. this.type = query.type;
  513. this.pageType = query.pageType;
  514. // this.form.type
  515. let tempTitle = {
  516. 1: "468px * 552px;图片不能超过 2M;",
  517. 2: "456px * 288px; 图片不能超过 2M;",
  518. 3: "686px * 140px; 图片不能超过 2M;",
  519. 4: "图片不能超过 2M;",
  520. 5: "图片不能超过 2M;",
  521. 6: "图片不能超过 2M;",
  522. 7: "图片不能超过 2M;",
  523. 8: "1242px * 2208px; 图片不能超过 2M;"
  524. };
  525. this.imageSize = tempTitle[this.form.type];
  526. this.$refs["form"].clearValidate();
  527. },
  528. addAdvVideo () {
  529. this.dialogFormVisible = true
  530. let dialogForm = this.dialogForm
  531. dialogForm.poster = this.form.videoCoverImage
  532. if (this.formRadio == 1) {
  533. dialogForm.url = this.form.coverImage
  534. } else {
  535. dialogForm.videoUrl = this.form.coverImage
  536. }
  537. this.uploadStatus = true
  538. },
  539. onVideoComfirm (formName) {
  540. this.$refs[formName].validate(valid => {
  541. if (valid) {
  542. let dialogForm = this.dialogForm;
  543. if (this.uploadStatus) {
  544. // 添加视频类型
  545. let form = this.form
  546. form.coverImage = this.formRadio == 1 ? dialogForm.url : dialogForm.videoUrl
  547. form.videoCoverImage = dialogForm.poster
  548. this.uploadStatus = false
  549. } else {
  550. // 编辑器输入视频
  551. // 获取富文本组件实例
  552. let quill = this.editor;
  553. // 插入图片,res为服务器返回的图片链接地址
  554. const params = {
  555. poster: dialogForm.poster,
  556. url: this.formRadio == 1 ? dialogForm.url : dialogForm.videoUrl,
  557. }
  558. quill.insertEmbed(this.editorIndex, "video", params);
  559. // 调整光标到最后
  560. quill.setSelection(this.editorIndex + 1, { preload: false });
  561. }
  562. this.dialogFormVisible = false;
  563. this.dialogForm = {
  564. poster: null,
  565. url: null,
  566. videoUrl: null
  567. };
  568. } else {
  569. return false;
  570. }
  571. });
  572. },
  573. onDialogClose (diologForm) {
  574. this.dialogForm = {
  575. poster: null,
  576. url: null,
  577. videoUrl: null
  578. }
  579. this.$refs[diologForm].resetFields()
  580. },
  581. addQuillTitle () {
  582. const oToolBar = document.querySelector(".ql-toolbar"),
  583. aButton = oToolBar.querySelectorAll("button"),
  584. aSelect = oToolBar.querySelectorAll("select");
  585. aButton.forEach(function (item) {
  586. if (item.className === "ql-script") {
  587. item.value === "sub" ? (item.title = "下标") : (item.title = "上标");
  588. } else if (item.className === "ql-indent") {
  589. item.value === "+1"
  590. ? (item.title = "向右缩进")
  591. : (item.title = "向左缩进");
  592. } else {
  593. item.title = titleConfig[item.classList[0]];
  594. }
  595. });
  596. aSelect.forEach(function (item) {
  597. item.parentNode.title = titleConfig[item.classList[0]];
  598. });
  599. },
  600. onSubmit (formName) {
  601. this.$refs[formName].validate(valid => {
  602. if (valid) {
  603. let { subjectIdList, organIdList, ...rest } = this.form
  604. let form = {
  605. ...rest,
  606. subjectIdList: subjectIdList ? subjectIdList.join(',') : null,
  607. organIdList: organIdList ? organIdList.join(',') : null
  608. }
  609. let actionTime = form.actionTime
  610. // console.log(actionTime)
  611. if(actionTime && actionTime.length > 0) {
  612. form.onlineTime = dayjs(actionTime[0]).format('YYYY-MM-DD HH:mm:ss')
  613. form.offlineTime = dayjs(actionTime[1]).format('YYYY-MM-DD HH:mm:ss')
  614. } else {
  615. form.onlineTime = null
  616. form.offlineTime = null
  617. }
  618. if (this.pageType == "create") {
  619. if (form.id) {
  620. // 判断有没有Id,如果有则删除
  621. delete form.id;
  622. }
  623. if(this.type == 5) {
  624. form.status = 0
  625. }
  626. // return false
  627. newsAdd(form).then(res => {
  628. this.messageTips("添加", res);
  629. });
  630. } else if (this.pageType == "update") {
  631. newsUpdate(form).then(res => {
  632. this.messageTips("修改", res);
  633. });
  634. }
  635. } else {
  636. this.$nextTick(() => {
  637. let isError = document.getElementsByClassName('is-error')
  638. isError[0].scrollIntoView({
  639. block: 'center',
  640. behavior: 'smooth',
  641. })
  642. })
  643. return false;
  644. }
  645. });
  646. },
  647. messageTips (title, res) {
  648. if (res.code == 200) {
  649. this.$message.success(title + "成功");
  650. this.$store.dispatch('delVisitedViews', this.$route)
  651. this.$router.push({
  652. path: "/contentManager/contentManager",
  653. query: {
  654. tabrouter: this.typeIndex(this.type)
  655. }
  656. });
  657. } else {
  658. this.$message.error(res.msg);
  659. }
  660. },
  661. onCancel () {
  662. this.$store.dispatch('delVisitedViews', this.$route)
  663. this.$router.push({
  664. path: "/contentManager/contentManager",
  665. query: {
  666. tabrouter: this.typeIndex(this.type)
  667. }
  668. });
  669. },
  670. handleSuccess (res) {
  671. // 获取富文本组件实例
  672. let quill = this.editor;
  673. // 如果上传成功
  674. if (res.code) {
  675. // 获取光标所在位置
  676. let length = quill.getSelection().index;
  677. // 插入图片,res为服务器返回的图片链接地址
  678. quill.insertEmbed(length, "image", res.data.url);
  679. // 调整光标到最后
  680. quill.setSelection(length + 1);
  681. } else {
  682. // 提示信息,需引入Message
  683. this.$message.error("图片插入失败");
  684. }
  685. },
  686. onReSet (formName) {
  687. const query = this.$route.query
  688. let url = ''
  689. if (query.type == 7) {
  690. url = vaildStudentUrl() + "/#/knowledge"
  691. } else if (query.type == 8 || query.type == 5) {
  692. url = ''
  693. } else {
  694. url = vaildStudentUrl() + "/#/specialdetail"
  695. }
  696. this.form = {
  697. title: null,
  698. order: null,
  699. coverImage: null,
  700. videoCoverImage: null,
  701. attribute1: null,
  702. linkUrl: url,
  703. type: query.type,
  704. status: 1,
  705. content: null,
  706. // tenantId: null,
  707. organIdList: null,
  708. subType: null,
  709. actionTime: null
  710. };
  711. this.$refs[formName].resetFields();
  712. },
  713. onLook () {
  714. // 预览
  715. let dataInfo = this.dataInfo
  716. dataInfo.title = this.form.title
  717. dataInfo.content = this.form.content
  718. // 处理图片显示问题
  719. setTimeout(() => {
  720. let imgNode = document.querySelectorAll(".msgWrap img");
  721. if (imgNode.length > 0) {
  722. imgNode.forEach(item => {
  723. item.style.width = "100%";
  724. });
  725. }
  726. let videoNode = document.querySelectorAll(".msgWrap .ql-video");
  727. if (videoNode.length > 0) {
  728. videoNode.forEach(item => {
  729. item.style.width = "100%";
  730. item.style.height = "195px";
  731. });
  732. }
  733. }, 500);
  734. this.lookVisible = true
  735. },
  736. async getList () {
  737. if(this.type == 7 || this.type == 2) {
  738. await newsTypeList({ parentId: this.type }).then(res => {
  739. console.log(res)
  740. if(res.code ==200) {
  741. this.typeList = res.data
  742. }
  743. })
  744. }
  745. if (this.pageType == "create") {
  746. return;
  747. } else {
  748. newsQueryId({ id: this.$route.query.id }).then(res => {
  749. if (res.code == 200) {
  750. let result = res.data;
  751. let form = this.form;
  752. if (result.videoCoverImage) {
  753. this.uploadType = 2
  754. } else {
  755. this.uploadType = 1
  756. }
  757. let tempActionTime = null
  758. if(result.onlineTime && result.offlineTime) {
  759. tempActionTime = [result.onlineTime, result.offlineTime]
  760. }
  761. let subject = result.subjectIdList ? result.subjectIdList.split(',') : []
  762. let organ = result.organIdList ? result.organIdList.split(',') : []
  763. this.form = {
  764. id: result.id,
  765. title: result.title,
  766. order: result.order,
  767. coverImage: result.coverImage,
  768. videoCoverImage: result.videoCoverImage,
  769. attribute1: Number(result.attribute1),
  770. linkUrl: result.linkUrl,
  771. type: result.type,
  772. status: result.status,
  773. // tenantId: result.tenantId.toString(),
  774. subjectIdList: subject.map(item => { return +item }),
  775. organIdList: organ.map(item => { return +item }),
  776. memo: result.memo,
  777. content: result.content,
  778. actionTime: tempActionTime,
  779. subType: result.subType ? result.subType : null
  780. };
  781. this.dataInfo.updateTime = result.updateTime
  782. }
  783. });
  784. }
  785. },
  786. handleUploadImgError (file) {
  787. this.uploadImgLoading = false
  788. this.$message.error('上传失败')
  789. },
  790. handleImgSuccess (res, file) {
  791. this.uploadImgLoading = false
  792. if (res.code == 200) {
  793. this.dialogForm.poster = res.data.url
  794. } else {
  795. this.$message.error('上传失败')
  796. }
  797. },
  798. beforeImgUpload (file) {
  799. const imageType = {
  800. "image/png": true,
  801. "image/jpeg": true,
  802. "image/gif": true
  803. };
  804. const isImage = imageType[file.type];
  805. const isLt2M = file.size / 1024 / 1024 < 2;
  806. // console.log(isImage, isLt2M)
  807. if (!isImage) {
  808. this.$message.error("只能上传图片格式!");
  809. }
  810. if (!isLt2M) {
  811. this.$message.error("上传图片大小不能超过 2MB!");
  812. }
  813. if (isImage && isLt2M) {
  814. this.uploadImgLoading = true
  815. }
  816. return isImage && isLt2M;
  817. },
  818. handleAvatarSuccess (res, file) {
  819. if (res.code == 200) {
  820. this.form.coverImage = res.data.url;
  821. } else {
  822. this.$message.error('上传失败')
  823. }
  824. },
  825. beforeAvatarUpload (file) {
  826. const imageType = {
  827. "image/png": true,
  828. "image/jpeg": true,
  829. "image/gif": true
  830. };
  831. const isImage = imageType[file.type];
  832. const isLt2M = file.size / 1024 / 1024 < 2;
  833. if (!isImage) {
  834. this.$message.error("只能上传图片格式!");
  835. }
  836. if (!isLt2M) {
  837. this.$message.error("上传图片大小不能超过 2M!");
  838. }
  839. return isImage && isLt2M;
  840. },
  841. typeChange (type) {
  842. let tempTitle = {
  843. 1: "精彩活动",
  844. 2: "热门资讯",
  845. 4: "专项训练",
  846. 5: "闪页管理",
  847. 3: "BANNER管理",
  848. 6: "APP按钮管理",
  849. 7: "知识库管理",
  850. 8: "广告管理"
  851. };
  852. return tempTitle[type];
  853. },
  854. typeCheck (type) {
  855. // 精彩活动 1 0
  856. // 热门资讯 2 1
  857. // 专项训练 4 2
  858. // 闪页管理 5 3
  859. // BANNER管理 3 4
  860. // APP按钮管理 6 5
  861. // 知识库 7 5
  862. let params = {
  863. 1: '精彩活动',
  864. 2: '热门资讯',
  865. 4: '专项训练',
  866. 7: '知识库'
  867. }
  868. return params[type] ? params[type] : '大雅乐盟'
  869. },
  870. typeIndex (type) {
  871. let tempTitle = {
  872. 1: 0,
  873. 2: 1,
  874. 3: 4,
  875. 4: 2,
  876. 5: 3,
  877. 6: 5,
  878. 7: 6,
  879. 8: 7
  880. };
  881. return tempTitle[type];
  882. },
  883. onEditorChange ({ quill, html, text }) {
  884. this.form.content = html;
  885. },
  886. beforeUpload (file) {
  887. // const isJPG = file.type === 'image/jpeg';
  888. const isLt2M = file.size / 1024 / 1024 < 100;
  889. // if (!isJPG) {
  890. // this.$message.error('上传头像图片只能是 JPG 格式!');
  891. // }
  892. if (!isLt2M) {
  893. this.$message.error('上传视频大小不能超过 100MB!');
  894. }
  895. this.uploadLoading = true
  896. return isLt2M;
  897. },
  898. handleUploadError (file) {
  899. this.uploadLoading = false
  900. this.$message.error('上传视频失败')
  901. },
  902. handleUploadSuccess (file, fileList) {
  903. this.uploadLoading = false
  904. if (file.code == 200) {
  905. this.$message.success('上传视频成功')
  906. this.dialogForm.videoUrl = file.data.url;
  907. } else {
  908. this.$message.error('上传视频失败')
  909. }
  910. },
  911. handleExceed (files, fileList) {
  912. this.$message.error('您已上传过视频')
  913. // this.$message.warning(`当前限制选择 1 个文件,本次选择了 ${files.length} 个文件,共选择了 ${files.length + fileList.length} 个文件`);
  914. }
  915. },
  916. computed: {
  917. editor () {
  918. return this.$refs.myQuillEditor.quill;
  919. }
  920. }
  921. };
  922. </script>
  923. <style lang="scss" scoped>
  924. .m-container {
  925. min-width: 100%;
  926. }
  927. .el-input {
  928. width: 400px;
  929. }
  930. /deep/.ql-editor {
  931. min-height: 300px;
  932. padding: 0;
  933. }
  934. /deep/.ql-container .ql-editor {
  935. max-height: 500px;
  936. }
  937. .el-row {
  938. margin-top: 40px;
  939. }
  940. .el-col {
  941. display: flex;
  942. align-items: center;
  943. margin-bottom: 20px;
  944. justify-content: flex-end;
  945. margin-right: 50%;
  946. }
  947. .el-input-group {
  948. width: 200px;
  949. margin: 0 20px;
  950. }
  951. /deep/.el-tree-node__content {
  952. height: 40px !important;
  953. }
  954. /deep/.avatar-uploader .el-upload,
  955. /deep/.upload-demo .el-upload {
  956. border-radius: 6px;
  957. cursor: pointer;
  958. position: relative;
  959. overflow: hidden;
  960. }
  961. .avatar-uploader .el-upload:hover {
  962. border-color: #409eff;
  963. }
  964. .avatar-uploader-icon {
  965. border: 1px dashed #d9d9d9;
  966. font-size: 28px;
  967. color: #8c939d;
  968. width: 120px;
  969. height: 120px;
  970. line-height: 120px;
  971. text-align: center;
  972. }
  973. .avatar {
  974. width: 120px;
  975. height: 120px;
  976. display: block;
  977. }
  978. .ivu-upload {
  979. display: none;
  980. }
  981. .sd-container {
  982. // padding: 15px;
  983. h2 {
  984. height: auto;
  985. font-weight: 500;
  986. color: rgba(68, 68, 68, 1);
  987. line-height: 37px;
  988. font-size: 26px;
  989. margin-bottom: 10px;
  990. }
  991. .titleInfo {
  992. height: 15px;
  993. line-height: 15px;
  994. display: flex;
  995. flex-direction: row;
  996. justify-content: space-between;
  997. color: #444;
  998. margin-bottom: 25px;
  999. }
  1000. .imgWrap {
  1001. /* width: 100;
  1002. height: 1.45rem; */
  1003. margin-bottom: 0.15rem;
  1004. p {
  1005. font-size: 0.16rem;
  1006. font-family: PingFangSC;
  1007. font-weight: 400;
  1008. color: rgba(68, 68, 68, 1);
  1009. line-height: 0.28rem;
  1010. text-indent: 0.32rem;
  1011. }
  1012. img {
  1013. width: 100%;
  1014. }
  1015. }
  1016. }
  1017. .imageSize {
  1018. color: red;
  1019. line-height: 1.5;
  1020. }
  1021. </style>