contentOperation.vue 28 KB

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