editor.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. <template>
  2. <div class="editor">
  3. <!--作品名称-->
  4. <div class="app__dp_f app__f_r app__alig_c">
  5. <h5 class="app__f_s_0"><span class="app__fc_r">*</span>作品名称</h5>
  6. <el-input type="textarea" :rows="1" resize="none" show-word-limit v-model="workName" class="app__ml_20" placeholder="50字符以内,不能包含&*\#等特殊字符"
  7. :maxlength="50" @blur="workNameBlur"/>
  8. </div>
  9. <!--作品描述-->
  10. <div class="app__dp_f app__f_r app__mt_10" style="align-items:flex-start">
  11. <h5 class="label app__mt_20 app__ws_nw app__f_s_0"><span class="app__fc_r">*</span>作品描述
  12. <span class="app__ml_10" style="display: none"><a>查看参考案例</a></span></h5>
  13. <el-input type="textarea" :rows="5" v-model="content" placeholder="请输入60-10000字的作品内容"
  14. :maxlength="10000" class="app__ml_20"/>
  15. </div>
  16. <!--作品链接-->
  17. <div class="app__dp_f app__f_r app__alig_c app__mt_20">
  18. <h5 class="app__f_s_0">作品链接</h5>
  19. <el-input show-word-limit v-model="workUrl" class="title _title" placeholder="例如:https://www.proginn.com 若无法添加作品有效链接,请添加作品截图" :maxlength="50"></el-input>
  20. </div>
  21. <!--作品封面图 -->
  22. <h5 class="label app__mt_20">作品截图(至少上传2张)</h5>
  23. <multi-uploader v-model="workImages"></multi-uploader>
  24. <h5 class="app__mt_35">作品资源</h5>
  25. <div class="app__mt_20">
  26. <el-upload style="display:inline-block"
  27. action="#"
  28. ref="upload"
  29. :on-success="handleSuccess"
  30. :on-change="uploadFileChange"
  31. :on-remove="uploadFileDelete"
  32. :on-err="uploadFileError"
  33. :multiple="false"
  34. :show-file-list="false"
  35. :file-list="uploadFileList">
  36. <div class=" app__f_r app__al_c">
  37. <button slot="trigger" class='app__bd_a_308EFF app__fc_308EFF app__fs_13 app_br_2 app__w_120 app__h_35 app__ta_c app__lh_35'
  38. v-if="uploadFileList.length === 0">
  39. 点击添加
  40. </button>
  41. <span slot="tip" class="app__fs_13 app__fc_999 app__ml_15" v-if="uploadFileList.length === 0">文件小于1GB,请勿上传侵权内容作品</span>
  42. </div>
  43. </el-upload>
  44. <div v-if="uploadFileList.length > 0" class="app__mw_40_p">
  45. <div class="app__f_r app__al_c">
  46. <p class="app__fs_15 app__txt_ellipsis">{{uploadFileList.length > 0 ? uploadFileList[0].name : ""}}</p>
  47. <button class="app__fc_999 app__fs_18 app__ml_20" @click="uploadFileDelete">x</button>
  48. </div>
  49. <el-progress :percentage="uploadPercentage" status="success" :stroke-width="8" class="app__mt_10"/>
  50. </div>
  51. </div>
  52. <footer class="app__tg_c">
  53. <el-button type="primary" @click="publish" class="btn-save" v-bind:disabled="isPublishing">保存</el-button>
  54. <!-- <el-button @click="cancel">取消</el-button>-->
  55. </footer>
  56. </div>
  57. </template>
  58. <script>
  59. import editor from "@/components/editor";
  60. import multiUploader from '@/components/multi-uploader';
  61. import axios from "axios";
  62. import oos from "../../mixins/oos";
  63. export default {
  64. head() {
  65. return {
  66. script: []
  67. };
  68. },
  69. components: {
  70. editor,
  71. multiUploader
  72. },
  73. data() {
  74. return {
  75. topicId: "", // 编辑
  76. hashID: null,
  77. workName: "",
  78. title: "",
  79. subTitle: "",
  80. content: "",
  81. cover_url: "",
  82. dialogVisible: false,
  83. disabled: false,
  84. collectionId: "",
  85. collectionList: [],
  86. categoryList: [
  87. {
  88. value: "default",
  89. label: "推荐"
  90. }
  91. ],
  92. fileList: [],
  93. uploading: false,
  94. workUrl: "",
  95. isPublishing: false,
  96. workImages: [],
  97. wid: "",
  98. work_up_url: "",
  99. workList: []
  100. };
  101. },
  102. mixins: [oos],
  103. computed: {},
  104. mounted() {
  105. this.needLogin();
  106. // this.needVerify();
  107. this.getHejiList();
  108. if (this.$route.query.wid) {
  109. this.getWorkDetail();
  110. this.getWorkFile();
  111. }
  112. console.log("url", this.$route.query.wid);
  113. },
  114. methods: {
  115. getWorkDetail(data) {
  116. this.$axios
  117. .$post(`/api/user_works/get_detail`, {wid: this.$route.query.wid})
  118. .then(res => {
  119. console.log(res);
  120. if (res.status == 1) {
  121. this.workName = res.data.name || "";
  122. this.content = res.data.description || "";
  123. this.setWorkImages(res.data);
  124. this.workUrl = res.data.url || ""
  125. }
  126. });
  127. },
  128. getWorkFile() {
  129. this.$axios.$post(`/api/UserWorks/getWorkFile`, {wid: this.$route.query.wid}).then(res => {
  130. console.log(res);
  131. if (res.status === 1) {
  132. this.uploadFileList.push({name: res.data.file_name, url: res.data.file_url_abs, path: res.data.file_url});
  133. console.log(this.uploadFileList)
  134. }
  135. }).catch(err => {
  136. console.log(err)
  137. });
  138. },
  139. setWorkImages(data) {
  140. let images = data.images;
  141. if (images && images.length > 0) {
  142. images.forEach((image, index) => {
  143. let imageName = this.getImageName(image.url);
  144. console.log("imageName", imageName);
  145. this.workImages.push({name: imageName + index, url: image.url});
  146. })
  147. }
  148. console.log(this.workImages);
  149. },
  150. getImageName(imageName) {
  151. if (imageName) {
  152. try {
  153. const lastquotaIndex = imageName.lastIndexOf("/");
  154. const lastDotIndex = imageName.lastIndexOf('.');
  155. return imageName.substring(lastquotaIndex + 1, lastDotIndex);
  156. } catch (e) {
  157. console.log(e);
  158. }
  159. }
  160. return "";
  161. },
  162. getHejiList() {
  163. this.$axios.post("/api/jishuquan/get_collections", {uid: this.$store.state.userinfo.uid, page: 1, size: 200}).then(res => {
  164. if (res.data.status === 1) {
  165. this.collectionList = res.data.data
  166. }
  167. })
  168. },
  169. /**
  170. * 发布项目作品
  171. */
  172. publish() {
  173. //防止快速连点
  174. if (this.isPublishing) {
  175. return;
  176. }
  177. this.isPublishing = true;
  178. const validCheckResult = this.publishValidCheck();
  179. if (!validCheckResult.success) {
  180. this.$message.error(validCheckResult.msg);
  181. this.isPublishing = false;
  182. return;
  183. }
  184. let workFile = this.uploadFileList.length > 0 ? this.uploadFileList[0].url : "";
  185. console.log(this.uploadFileList);
  186. const data = {
  187. name: this.workName,
  188. description: this.content,
  189. url: this.workUrl,
  190. image_list: this.workImages.map((it) => it.url).join(","),
  191. work_file: workFile
  192. };
  193. if (this.$route.query.wid) {
  194. data.wid = this.$route.query.wid;
  195. this.$axios.$post(`/api/user_works/update`, data).then(res => {
  196. console.log(res);
  197. if (res.status === -99) {
  198. this.goHome();
  199. }
  200. if (res.status === 1) {
  201. this.$message.success("编辑成功!");
  202. // window.location.href = res.data.work_url;
  203. } else {
  204. this.$message.error("编辑提交失败,请重试");
  205. }
  206. this.isPublishing = false;
  207. });
  208. } else {
  209. this.$axios.$post(`/api/user_works/add`, data).then(res => {
  210. console.log(res);
  211. if (res.status === -99) {
  212. this.goHome();
  213. }
  214. if (res.status === 1) {
  215. this.$message.success("发布成功!");
  216. this.$router.go(-1);
  217. }
  218. this.isPublishing = false;
  219. });
  220. }
  221. },
  222. /**
  223. * 输入合法性检查
  224. * @return {{msg: string, success: boolean}}
  225. */
  226. publishValidCheck() {
  227. if (!this.workName) {
  228. return {success: false, msg: "请输入项目名称"};
  229. }
  230. if (this.workName.length < 2) {
  231. return {success: false, msg: "项目名称不可少于2字符"};
  232. }
  233. if (this.title.length > 50) {
  234. return {success: false, msg: "文章标题不可超过50字符,请删减"};
  235. }
  236. if (!this.content) {
  237. return {success: false, msg: "请输入项目正文"};
  238. }
  239. if (this.content.length < 60) {
  240. return {success: false, msg: "项目正文不可少于60字符"};
  241. }
  242. if (this.content.length > 10000) {
  243. return {success: false, msg: "项目正文不可大于10000字符,请删减"};
  244. }
  245. if (this.workImages.length < 2) {
  246. return {success: false, msg: "至少上传2张作品截图"};
  247. }
  248. return {success: true, msg: ""}
  249. },
  250. cancel() {
  251. this.$router.back();
  252. },
  253. handleChange(val) {
  254. this.content = val;
  255. },
  256. handleDeleteFile() {
  257. this.cover_url = "";
  258. },
  259. handleFileChange(file) {
  260. console.log(file);
  261. if (file.size / 1024 > 2048) {
  262. this.$message.error("图片大小不得超过2M,请重新选择");
  263. return false;
  264. }
  265. const formData = new FormData();
  266. formData.append("target", '{ "type": 3 }');
  267. formData.append("id", "WU_FILE_0");
  268. formData.append("name", file.name);
  269. formData.append("type", file.type);
  270. formData.append("lastModifiedDate", file.lastModifiedDate);
  271. formData.append("size", file.size);
  272. formData.append("file", file);
  273. this.$axios.$post(`/file/proxyUpload`, formData, {headers: {"Content-Type": "multipart/form-data"}}).then(res => {
  274. this.cover_url = (res.data && res.data.url) || "";
  275. this.fileList = [
  276. {
  277. name: "file.name",
  278. url: this.cover_url
  279. }
  280. ];
  281. });
  282. },
  283. workNameBlur(e) {
  284. this.workName = this.workName.replace(/[&|\*|#|\\]/g, "");
  285. },
  286. handleSuccess(response, file, fileList) {
  287. },
  288. },
  289. };
  290. </script>
  291. <style lang="scss">
  292. @import "../../assets/css/common.css";
  293. @import "../../assets/css/public.css";
  294. .editor {
  295. position: relative;
  296. padding: 20px 100px;
  297. /*width: 740px;*/
  298. background: #fff;
  299. .title,
  300. .sub-title {
  301. .el-input__inner {
  302. padding: 0;
  303. border: 0;
  304. border-radius: 0;
  305. }
  306. }
  307. .title {
  308. margin: 10px auto 20px;
  309. font-size: 28px;
  310. font-family: PingFangSC-Medium;
  311. font-weight: 500;
  312. color: rgba(29, 42, 58, 1);
  313. line-height: 40px;
  314. }
  315. ._title {
  316. font-size: 15px !important;
  317. margin: 0 0 0 20px !important;
  318. border-bottom: 1px solid #ddd;
  319. }
  320. .sub-title {
  321. margin-bottom: 28px;
  322. min-height: 18px;
  323. font-size: 14px;
  324. font-family: PingFangSC-Regular;
  325. font-weight: 400;
  326. color: rgba(145, 154, 167, 1);
  327. line-height: 18px;
  328. border: 0;
  329. .el-textarea__inner {
  330. height: 18px;
  331. line-height: 18px;
  332. border: 0;
  333. padding-left: 0;
  334. }
  335. }
  336. .label {
  337. margin: 20px auto 10px;
  338. font-size: 13px;
  339. font-family: PingFangSC-Medium;
  340. font-weight: 500;
  341. color: rgba(25, 34, 46, 1);
  342. line-height: 18px;
  343. }
  344. .ql-toolbar {
  345. border-width: 1px 0 0 0 !important;
  346. }
  347. .quill-editor {
  348. height: 450px;
  349. border-left: 0 !important;
  350. border-right: 0 !important;
  351. font-size: 14px;
  352. line-height: 25px;
  353. }
  354. .ql-snow.ql-toolbar::after {
  355. display: inline-block;
  356. }
  357. .class {
  358. width: 320px;
  359. }
  360. .tags {
  361. width: 560px;
  362. }
  363. footer {
  364. margin: 40px 0;
  365. /*button {*/
  366. /* width: 100px;*/
  367. /* height: 40px;*/
  368. /* border-radius: 0;*/
  369. /*}*/
  370. }
  371. strong {
  372. font-weight: 800 !important;
  373. }
  374. em {
  375. font-style: italic !important;
  376. }
  377. }
  378. .uploadInfo {
  379. display: flex;
  380. padding-left: 30px;
  381. align-items: center;
  382. .left {
  383. width: 150px;
  384. height: 180px;
  385. flex-shrink: 0;
  386. overflow: hidden;
  387. position: relative;
  388. background: #fff;
  389. .el-icon-delete {
  390. display: none;
  391. }
  392. .avatar-uploader .el-upload {
  393. width: 150px;
  394. height: 150px;
  395. border: 1px dashed #dce1e8;
  396. border-radius: 6px;
  397. cursor: pointer;
  398. position: relative;
  399. overflow: hidden;
  400. img {
  401. width: 100%;
  402. height: auto;
  403. object-fit: contain;
  404. object-position: top left;
  405. }
  406. }
  407. .avatar-uploader .el-upload:hover {
  408. border-color: #409eff;
  409. .el-icon-plus {
  410. color: #409eff
  411. }
  412. .el-p-upload {
  413. color: #409eff
  414. }
  415. .el-icon-delete {
  416. display: block;
  417. }
  418. }
  419. .avatar-uploader-icon {
  420. /*position: absolute;*/
  421. /*top: 0;*/
  422. /*left: 0;*/
  423. font-size: 44px;
  424. color: #dce1e8;;
  425. /*width: 150px;*/
  426. /*height: 150px;*/
  427. /*line-height: 140px;*/
  428. text-align: center;
  429. }
  430. .el-p-upload {
  431. color: #dce1e8
  432. }
  433. .avatar {
  434. width: 180px;
  435. height: 140px;
  436. display: block;
  437. }
  438. .title {
  439. position: absolute;
  440. left: 50%;
  441. bottom: 40px;
  442. transform: translateX(-50%);
  443. font-size: 13px;
  444. font-weight: 500;
  445. color: #dce1e8;
  446. line-height: 18px;
  447. text-decoration: underline;
  448. }
  449. }
  450. .right {
  451. margin-left: 18px;
  452. height: 34px;
  453. p {
  454. font-size: 12px;
  455. font-weight: 400;
  456. color: rgba(145, 154, 167, 1);
  457. line-height: 17px;
  458. }
  459. }
  460. }
  461. .btn-save {
  462. width: 20vw;
  463. border-radius: 5px;
  464. }
  465. </style>