editor.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  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" @blur="workContentBlur" 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. <!-- <div class="uploadInfo">-->
  25. <!-- <div class="left">-->
  26. <!-- <el-upload class="avatar-uploader" action="#" :show-file-list="false" :multiple="false" accept="image/png, image/jpeg"-->
  27. <!-- :before-upload="handleFileChange">-->
  28. <!-- <i v-if="cover_url" class="el-icon-delete avatar-uploader-icon" @click.stop="handleDeleteFile"></i>-->
  29. <!-- <img v-if="cover_url" :src="cover_url" class="avatar"/>-->
  30. <!-- &lt;!&ndash;无照片&ndash;&gt;-->
  31. <!-- <div v-else class="app__dp_f app__f_c app__alig_c app__jus__c" style="height: 100%">-->
  32. <!-- <i class="el-icon-plus avatar-uploader-icon"></i>-->
  33. <!-- <p class="app__fz_12 app__mt_10 el-p-upload">上传照片</p>-->
  34. <!-- </div>-->
  35. <!-- </el-upload>-->
  36. <!-- <p class="app__fz_12 app__mt_10 app__tg_c app__fc_grey">支持JPG、PNG格式</p>-->
  37. <!-- </div>-->
  38. <!-- <div class="right">-->
  39. <!-- <p>(800*800,图片最大2M,最多一张)</p>-->
  40. <!-- </div>-->
  41. <!-- </div>-->
  42. <footer class="app__tg_c">
  43. <el-button type="primary" @click="publish" class="btn-save" v-bind:disabled="isPublishing">保存</el-button>
  44. <!-- <el-button @click="cancel">取消</el-button>-->
  45. </footer>
  46. </div>
  47. </template>
  48. <script>
  49. import editor from "@/components/editor";
  50. import multiUploader from '@/components/multi-uploader';
  51. export default {
  52. head() {
  53. return {
  54. script: []
  55. };
  56. },
  57. components: {
  58. editor,
  59. multiUploader
  60. },
  61. data() {
  62. return {
  63. topicId: "", // 编辑
  64. hashID: null,
  65. workName: "",
  66. title: "",
  67. subTitle: "",
  68. content: "",
  69. cover_url: "",
  70. dialogVisible: false,
  71. disabled: false,
  72. collectionId: "",
  73. collectionList: [],
  74. categoryList: [
  75. {
  76. value: "default",
  77. label: "推荐"
  78. }
  79. ],
  80. fileList: [],
  81. uploading: false,
  82. workUrl: "",
  83. isPublishing: false,
  84. workImages: []
  85. };
  86. },
  87. computed: {},
  88. mounted() {
  89. this.needLogin();
  90. // this.needVerify();
  91. this.getHejiList();
  92. if (this.$route.query.wid) {
  93. this.getWorkDetail();
  94. }
  95. console.log("url", this.$route.query.wid);
  96. },
  97. methods: {
  98. getWorkDetail(data) {
  99. this.$axios
  100. .$post(`/api/user_works/get_detail`, {wid: this.$route.query.wid})
  101. .then(res => {
  102. console.log(res);
  103. if (res.status == 1) {
  104. this.workName = res.data.name || "";
  105. this.content = res.data.description || "";
  106. this.cover_url = res.data.images && res.data.images.length > 0 ? res.data.images[0].thumbnail : "";
  107. this.workUrl = res.data.url || "123"
  108. }
  109. });
  110. // this.content = "123";
  111. },
  112. getHejiList() {
  113. this.$axios.post("/api/jishuquan/get_collections", {uid: this.$store.state.userinfo.uid, page: 1, size: 200}).then(res => {
  114. if (res.data.status === 1) {
  115. this.collectionList = res.data.data
  116. }
  117. })
  118. },
  119. /**
  120. * 发布项目作品
  121. */
  122. publish() {
  123. //防止快速连点
  124. if (this.isPublishing) {
  125. return;
  126. }
  127. this.isPublishing = true;
  128. if (this.workImages.length < 2) {
  129. this.$message.error("至少上传2张作品截图");
  130. return;
  131. }
  132. const validCheckResult = this.publishValidCheck();
  133. if (!validCheckResult.success) {
  134. this.$message.error(validCheckResult.msg);
  135. this.isPublishing = false;
  136. return;
  137. }
  138. const data = {name: this.workName, description: this.content, url: this.workUrl, image_list: this.workImages};
  139. if (this.$route.query.wid) {
  140. data.wid = this.$route.query.wid;
  141. this.$axios.$post(`/api/user_works/update`, data).then(res => {
  142. console.log(res);
  143. if (res.status === -99) {
  144. this.goHome();
  145. }
  146. if (res.status === 1) {
  147. this.$message.success("编辑成功!");
  148. // TODO go details
  149. window.location.href = `/wd/` + this.$route.query.wid;
  150. } else {
  151. this.$message.error("编辑提交失败,请重试");
  152. }
  153. this.isPublishing = false;
  154. });
  155. } else {
  156. this.$axios.$post(`/api/user_works/add`, data).then(res => {
  157. console.log(res);
  158. if (res.status === -99) {
  159. this.goHome();
  160. }
  161. if (res.status === 1) {
  162. this.$message.success("发布成功!");
  163. this.$router.go(-1);
  164. }
  165. this.isPublishing = false;
  166. });
  167. }
  168. },
  169. /**
  170. * 输入合法性检查
  171. * @return {{msg: string, success: boolean}}
  172. */
  173. publishValidCheck() {
  174. if (!this.workName) {
  175. return {success: false, msg: "请输入项目名称"};
  176. }
  177. if (this.workName.length < 2) {
  178. return {success: false, msg: "项目名称不可少于2字符"};
  179. }
  180. if (this.title.length > 50) {
  181. return {success: false, msg: "文章标题不可超过50字符,请删减"};
  182. }
  183. if (!this.content) {
  184. return {success: false, msg: "请输入项目正文"};
  185. }
  186. if (this.content.length < 60) {
  187. return {success: false, msg: "项目正文不可少于60字符"};
  188. }
  189. if (this.content.length > 10000) {
  190. return {success: false, msg: "项目正文不可大于10000字符,请删减"};
  191. }
  192. return {success: true, msg: ""};
  193. },
  194. cancel() {
  195. this.$router.back();
  196. },
  197. handleChange(val) {
  198. this.content = val;
  199. },
  200. handleDeleteFile() {
  201. this.cover_url = "";
  202. },
  203. handleFileChange(file) {
  204. console.log(file);
  205. if (file.size / 1024 > 2048) {
  206. this.$message.error("图片大小不得超过2M,请重新选择");
  207. return false;
  208. }
  209. const formData = new FormData();
  210. formData.append("target", '{ "type": 3 }');
  211. formData.append("id", "WU_FILE_0");
  212. formData.append("name", file.name);
  213. formData.append("type", file.type);
  214. formData.append("lastModifiedDate", file.lastModifiedDate);
  215. formData.append("size", file.size);
  216. formData.append("file", file);
  217. this.$axios
  218. .$post(`/file/proxyUpload`, formData, {
  219. headers: {"Content-Type": "multipart/form-data"}
  220. })
  221. .then(res => {
  222. this.cover_url = (res.data && res.data.url) || "";
  223. this.fileList = [
  224. {
  225. name: "file.name",
  226. url: this.cover_url
  227. }
  228. ];
  229. });
  230. },
  231. workNameBlur(e) {
  232. this.workName = this.workName.replace(/[&|\*|#|\\]/g, "");
  233. },
  234. // handleChange(e) {
  235. // console.log(e);
  236. // }
  237. }
  238. };
  239. </script>
  240. <style lang="scss">
  241. @import "../../assets/css/common.css";
  242. @import "../../assets/css/public.css";
  243. .editor {
  244. position: relative;
  245. padding: 20px 100px;
  246. /*width: 740px;*/
  247. background: #fff;
  248. .title,
  249. .sub-title {
  250. .el-input__inner {
  251. padding: 0;
  252. border: 0;
  253. border-radius: 0;
  254. }
  255. }
  256. .title {
  257. margin: 10px auto 20px;
  258. font-size: 28px;
  259. font-family: PingFangSC-Medium;
  260. font-weight: 500;
  261. color: rgba(29, 42, 58, 1);
  262. line-height: 40px;
  263. }
  264. ._title {
  265. font-size: 15px !important;
  266. margin: 0 0 0 20px !important;
  267. border-bottom: 1px solid #ddd;
  268. }
  269. .sub-title {
  270. margin-bottom: 28px;
  271. min-height: 18px;
  272. font-size: 14px;
  273. font-family: PingFangSC-Regular;
  274. font-weight: 400;
  275. color: rgba(145, 154, 167, 1);
  276. line-height: 18px;
  277. border: 0;
  278. .el-textarea__inner {
  279. height: 18px;
  280. line-height: 18px;
  281. border: 0;
  282. padding-left: 0;
  283. }
  284. }
  285. .label {
  286. margin: 20px auto 10px;
  287. font-size: 13px;
  288. font-family: PingFangSC-Medium;
  289. font-weight: 500;
  290. color: rgba(25, 34, 46, 1);
  291. line-height: 18px;
  292. }
  293. .ql-toolbar {
  294. border-width: 1px 0 0 0 !important;
  295. }
  296. .quill-editor {
  297. height: 450px;
  298. border-left: 0 !important;
  299. border-right: 0 !important;
  300. font-size: 14px;
  301. line-height: 25px;
  302. }
  303. .ql-snow.ql-toolbar::after {
  304. display: inline-block;
  305. }
  306. .class {
  307. width: 320px;
  308. }
  309. .tags {
  310. width: 560px;
  311. }
  312. footer {
  313. margin: 40px 0;
  314. /*button {*/
  315. /* width: 100px;*/
  316. /* height: 40px;*/
  317. /* border-radius: 0;*/
  318. /*}*/
  319. }
  320. strong {
  321. font-weight: 800 !important;
  322. }
  323. em {
  324. font-style: italic !important;
  325. }
  326. }
  327. .uploadInfo {
  328. display: flex;
  329. padding-left: 30px;
  330. align-items: center;
  331. .left {
  332. width: 150px;
  333. height: 180px;
  334. flex-shrink: 0;
  335. overflow: hidden;
  336. position: relative;
  337. background: #fff;
  338. .el-icon-delete {
  339. display: none;
  340. }
  341. .avatar-uploader .el-upload {
  342. width: 150px;
  343. height: 150px;
  344. border: 1px dashed #dce1e8;
  345. border-radius: 6px;
  346. cursor: pointer;
  347. position: relative;
  348. overflow: hidden;
  349. img {
  350. width: 100%;
  351. height: auto;
  352. object-fit: contain;
  353. object-position: top left;
  354. }
  355. }
  356. .avatar-uploader .el-upload:hover {
  357. border-color: #409eff;
  358. .el-icon-plus {
  359. color: #409eff
  360. }
  361. .el-p-upload {
  362. color: #409eff
  363. }
  364. .el-icon-delete {
  365. display: block;
  366. }
  367. }
  368. .avatar-uploader-icon {
  369. /*position: absolute;*/
  370. /*top: 0;*/
  371. /*left: 0;*/
  372. font-size: 44px;
  373. color: #dce1e8;;
  374. /*width: 150px;*/
  375. /*height: 150px;*/
  376. /*line-height: 140px;*/
  377. text-align: center;
  378. }
  379. .el-p-upload {
  380. color: #dce1e8
  381. }
  382. .avatar {
  383. width: 180px;
  384. height: 140px;
  385. display: block;
  386. }
  387. .title {
  388. position: absolute;
  389. left: 50%;
  390. bottom: 40px;
  391. transform: translateX(-50%);
  392. font-size: 13px;
  393. font-weight: 500;
  394. color: #dce1e8;
  395. line-height: 18px;
  396. text-decoration: underline;
  397. }
  398. }
  399. .right {
  400. margin-left: 18px;
  401. height: 34px;
  402. p {
  403. font-size: 12px;
  404. font-weight: 400;
  405. color: rgba(145, 154, 167, 1);
  406. line-height: 17px;
  407. }
  408. }
  409. }
  410. .btn-save {
  411. width: 20vw;
  412. border-radius: 5px;
  413. }
  414. </style>