editor.vue 11 KB

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