editor.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. <template>
  2. <div class="editor">
  3. <!-- title -->
  4. <div class="work-title">{{ this.wid ? '编辑' : '添加' }}项目作品</div>
  5. <!--作品名称-->
  6. <div class="work-field" style="margin-top: 30px;">
  7. <div class="work-label"><span class="app__fc_r">*</span> 作品名称</div>
  8. <el-input type="textarea" :rows="1" resize="none" show-word-limit v-model="workName" class="" placeholder="50字符以内,不能包含&*\#等特殊字符"
  9. :maxlength="50" @blur="workNameBlur"/>
  10. </div>
  11. <!--作品描述-->
  12. <div class="work-field" style="align-items:flex-start">
  13. <div class="work-label"><span class="app__fc_r">*</span> 作品描述</div>
  14. <el-input type="textarea" :rows="5" v-model="content" placeholder="请输入60-10000字的作品内容"
  15. :maxlength="10000" class=""/>
  16. </div>
  17. <!--作品链接-->
  18. <div class="work-field">
  19. <div class="work-label">作品链接</div>
  20. <el-input v-model="workUrl" class="title _title" placeholder="例如:https://www.proginn.com 若无法添加作品有效链接,请添加作品截图"></el-input>
  21. </div>
  22. <!--作品封面图 -->
  23. <div class="work-field">
  24. <div class="work-label" style="margin-bottom: 10px;"><span class="app__fc_r">*</span> 作品截图(至少2张)</div>
  25. <multi-uploader v-model="workImages"></multi-uploader>
  26. </div>
  27. <!-- 作品资源 -->
  28. <div class="work-field">
  29. <div class="work-label" style="margin-bottom: 10px;">作品资源<span class="upload-tips">文件小于1GB,请勿上传侵权内容作品</span></div>
  30. <div class="">
  31. <el-upload
  32. style="display:inline-block"
  33. action="#"
  34. ref="upload"
  35. :on-success="handleSuccess"
  36. :on-change="uploadFileChange"
  37. :on-remove="uploadFileDelete"
  38. :on-err="uploadFileError"
  39. :multiple="false"
  40. :show-file-list="false"
  41. :file-list="uploadFileList">
  42. <div class=" app__f_r app__al_c">
  43. <button slot="trigger" class='upload-btn' v-if="uploadFileList.length === 0">
  44. 点击添加
  45. </button>
  46. </div>
  47. </el-upload>
  48. <div v-if="uploadFileList.length > 0" class="app__mw_40_p">
  49. <div class="app__f_r app__al_c">
  50. <p class="app__fs_15 app__txt_ellipsis">{{uploadFileList.length > 0 ? uploadFileList[0].name : ""}}</p>
  51. <button class="app__fc_999 app__fs_18 app__ml_20" @click="uploadFileDelete">x</button>
  52. </div>
  53. <el-progress :percentage="uploadPercentage" status="success" :stroke-width="8" class="app__mt_10"/>
  54. </div>
  55. </div>
  56. </div>
  57. <!-- 所属分类 & 作品类型 -->
  58. <div class="work-field" v-if="uploadFileList.length > 0">
  59. <div class="work-label"><span class="app__fc_r">*</span> 所属分类</div>
  60. <div class="work-cate-type">
  61. <el-cascader
  62. class="work-cate-cascader"
  63. v-model="selectedWorkCate"
  64. :options="workCate"
  65. :props="{ expandTrigger: 'hover' }"
  66. placeholder="请选择作品分类"></el-cascader>
  67. </div>
  68. </div>
  69. <!-- 资源价格 -->
  70. <div class="work-field" v-if="uploadFileList.length > 0">
  71. <div class="work-label"><span class="app__fc_r">*</span> 资源价格</div>
  72. <div class="work-price-wrapper">
  73. <el-input
  74. class="work-price-input"
  75. type="number"
  76. placeholder="请输入资源价格"
  77. v-model="price"></el-input>
  78. <span>元</span>
  79. </div>
  80. </div>
  81. <!-- btn group -->
  82. <footer class="">
  83. <el-button type="primary" @click="publish" class="btn-save" v-bind:disabled="isPublishing">保存</el-button>
  84. <!-- <el-button @click="cancel">取消</el-button>-->
  85. </footer>
  86. </div>
  87. </template>
  88. <script>
  89. import editor from "@/components/editor";
  90. import multiUploader from '@/components/multi-uploader';
  91. import axios from "axios";
  92. import oos from "../../mixins/oos";
  93. export default {
  94. head() {
  95. return {
  96. script: []
  97. };
  98. },
  99. components: {
  100. editor,
  101. multiUploader
  102. },
  103. data() {
  104. return {
  105. topicId: "", // 编辑
  106. hashID: null,
  107. workName: "",
  108. title: "",
  109. subTitle: "",
  110. content: "",
  111. cover_url: "",
  112. dialogVisible: false,
  113. disabled: false,
  114. collectionId: "",
  115. collectionList: [],
  116. categoryList: [
  117. {
  118. value: "default",
  119. label: "推荐"
  120. }
  121. ],
  122. fileList: [],
  123. uploading: false,
  124. workUrl: "",
  125. isPublishing: false,
  126. workImages: [],
  127. wid: "",
  128. work_up_url: "",
  129. workList: [],
  130. // 所属分类
  131. workCate: [],
  132. selectedWorkCate: [],
  133. // 资源类型: 1 免费,2 付费
  134. workType: 1,
  135. // 资源价格
  136. price: 1
  137. };
  138. },
  139. mixins: [oos],
  140. computed: {},
  141. mounted() {
  142. this.needLogin();
  143. this.getWorkCate();
  144. // this.needVerify();
  145. // this.getHejiList();
  146. this.wid = this.$route.query.wid || ''
  147. if (this.wid) {
  148. this.getWorkDetail();
  149. this.getWorkFile();
  150. }
  151. console.log("url", this.$route.query.wid);
  152. },
  153. methods: {
  154. getWorkDetail(data) {
  155. this.$axios
  156. .$post(`/api/user_works/get_detail`, {wid: this.$route.query.wid})
  157. .then(res => {
  158. console.log(res);
  159. if (res.status == 1) {
  160. this.workName = res.data.name || "";
  161. this.content = res.data.description || "";
  162. this.setWorkImages(res.data);
  163. this.workUrl = res.data.url || ""
  164. if (res.data.cate_id_one && res.data.cate_id_two) {
  165. this.selectedWorkCate = [res.data.cate_id_one, res.data.cate_id_two]
  166. }
  167. this.workType = res.data.price > 0 ? 2 : 1
  168. this.price = res.data.price || 0
  169. }
  170. });
  171. },
  172. getWorkFile() {
  173. this.$axios.$post(`/api/UserWorks/getWorkFile`, {wid: this.$route.query.wid}).then(res => {
  174. console.log(res);
  175. if (res.status === 1) {
  176. this.uploadFileList.push({name: res.data.file_name, url: res.data.file_url_abs, path: res.data.file_url});
  177. console.log(this.uploadFileList)
  178. }
  179. }).catch(err => {
  180. console.log(err)
  181. });
  182. },
  183. /**
  184. * 获取作品分类
  185. */
  186. getWorkCate() {
  187. this.$axios.$post('/api/user_works/cate').then(res => {
  188. if (res.status === 1) {
  189. let workCate = res.data || []
  190. this.workCate = workCate.map(item => {
  191. let children = item.child.map(child => {
  192. return {
  193. value: child.category_id,
  194. label: child.name
  195. }
  196. })
  197. return {
  198. value: item.category_id,
  199. label: item.name,
  200. children: children
  201. }
  202. })
  203. }
  204. }).catch(err => {
  205. console.log('get work cate error: ', err)
  206. })
  207. },
  208. setWorkImages(data) {
  209. let images = data.images;
  210. if (images && images.length > 0) {
  211. images.forEach((image, index) => {
  212. let imageName = this.getImageName(image.url);
  213. console.log("imageName", imageName);
  214. this.workImages.push({name: imageName + index, url: image.url});
  215. })
  216. }
  217. console.log(this.workImages);
  218. },
  219. getImageName(imageName) {
  220. if (imageName) {
  221. try {
  222. const lastquotaIndex = imageName.lastIndexOf("/");
  223. const lastDotIndex = imageName.lastIndexOf('.');
  224. return imageName.substring(lastquotaIndex + 1, lastDotIndex);
  225. } catch (e) {
  226. console.log(e);
  227. }
  228. }
  229. return "";
  230. },
  231. getHejiList() {
  232. this.$axios.post("/api/jishuquan/get_collections", {uid: this.$store.state.userinfo.uid, page: 1, size: 200}).then(res => {
  233. if (res.data.status === 1) {
  234. this.collectionList = res.data.data
  235. }
  236. })
  237. },
  238. /**
  239. * 发布项目作品
  240. */
  241. publish() {
  242. const self = this;
  243. //防止快速连点
  244. if (this.isPublishing) {
  245. return;
  246. }
  247. this.isPublishing = true;
  248. const validCheckResult = this.publishValidCheck();
  249. if (!validCheckResult.success) {
  250. this.$message.error(validCheckResult.msg);
  251. this.isPublishing = false;
  252. return;
  253. }
  254. let workFile = this.uploadFileList.length > 0 ? this.uploadFileList[0].url : "";
  255. console.log(this.uploadFileList);
  256. const data = {
  257. name: this.workName,
  258. description: this.content,
  259. url: this.workUrl,
  260. image_list: this.workImages.map((it) => it.url).join(","),
  261. work_file: workFile,
  262. type: this.workType,
  263. cate_id_one: this.selectedWorkCate[0],
  264. cate_id_two: this.selectedWorkCate[1],
  265. price: this.price
  266. };
  267. if (this.wid) {
  268. data.wid = this.wid;
  269. this.$axios.$post(`/api/user_works/update`, data).then(res => {
  270. console.log(res);
  271. if (res.status === -99) {
  272. this.goHome();
  273. }
  274. if (res.status === 1) {
  275. this.$message.success("编辑作品成功!");
  276. setTimeout(() => {
  277. //window.location.href = `/wo/${self.$store.state.userinfo.uid}/works`;
  278. window.location.href = res.data.work_url;
  279. }, 800);
  280. // window.location.href = res.data.work_url;
  281. } else {
  282. this.$message.error("编辑作品失败,请重试");
  283. }
  284. this.isPublishing = false;
  285. });
  286. } else {
  287. this.$axios.$post(`/api/user_works/add`, data).then(res => {
  288. console.log(res);
  289. if (res.status === -99) {
  290. this.goHome();
  291. }
  292. if (res.status === 1) {
  293. this.$message.success("添加作品成功!");
  294. this.wid = res.data.wid || ''
  295. setTimeout(() => {
  296. window.location.href = res.data.work_url;
  297. }, 800);
  298. } else {
  299. this.$message.error("添加作品失败,请重试");
  300. }
  301. this.isPublishing = false;
  302. });
  303. }
  304. },
  305. /**
  306. * 输入合法性检查
  307. * @return {{msg: string, success: boolean}}
  308. */
  309. publishValidCheck() {
  310. if (!this.workName) {
  311. return {success: false, msg: "请输入作品名称"};
  312. }
  313. if (this.workName.length < 2) {
  314. return {success: false, msg: "作品名称不可少于2字符"};
  315. }
  316. if (this.workName.length > 50) {
  317. return {success: false, msg: "作品名称不可超过50字符,请删减"};
  318. }
  319. if (!this.content) {
  320. return {success: false, msg: "请输入作品描述"};
  321. }
  322. if (this.content.length < 60) {
  323. return {success: false, msg: "作品描述不可少于60字符"};
  324. }
  325. if (this.content.length > 10000) {
  326. return {success: false, msg: "作品描述不可大于10000字符,请删减"};
  327. }
  328. if (this.workImages.length < 2) {
  329. return {success: false, msg: "至少上传2张作品截图"};
  330. }
  331. // 上传文件后,才需要填写分类及价格
  332. if (this.uploadFileList.length) {
  333. if (this.selectedWorkCate.length !== 2 || (!this.selectedWorkCate[0] || !this.selectedWorkCate[1])) {
  334. return {success: false, msg: "请选择作品分类"};
  335. }
  336. if (this.price <= 0) {
  337. //return {success: false, msg: "请输入大于0的资源价格"};
  338. }
  339. if (String(this.price).indexOf('.') > -1 &&
  340. String(this.price).length - String(this.price).indexOf('.') - 1 > 2) {
  341. return {success: false, msg: "资源价格最多保留两位小数"};
  342. }
  343. }
  344. return {success: true, msg: ""}
  345. },
  346. cancel() {
  347. this.$router.back();
  348. },
  349. handleChange(val) {
  350. this.content = val;
  351. },
  352. handleDeleteFile() {
  353. this.cover_url = "";
  354. },
  355. handleFileChange(file) {
  356. console.log(file);
  357. if (file.size / 1024 > 2048) {
  358. this.$message.error("图片大小不得超过2M,请重新选择");
  359. return false;
  360. }
  361. const formData = new FormData();
  362. formData.append("target", '{ "type": 3 }');
  363. formData.append("id", "WU_FILE_0");
  364. formData.append("name", file.name);
  365. formData.append("type", file.type);
  366. formData.append("lastModifiedDate", file.lastModifiedDate);
  367. formData.append("size", file.size);
  368. formData.append("file", file);
  369. this.$axios.$post(`/file/proxyUpload`, formData, {headers: {"Content-Type": "multipart/form-data"}}).then(res => {
  370. this.cover_url = (res.data && res.data.url) || "";
  371. this.fileList = [
  372. {
  373. name: "file.name",
  374. url: this.cover_url
  375. }
  376. ];
  377. });
  378. },
  379. workNameBlur(e) {
  380. this.workName = this.workName.replace(/[&|\*|#|\\]/g, "");
  381. },
  382. handleSuccess(response, file, fileList) {
  383. },
  384. showUploadTips () {
  385. this.$message.info('先保存项目作品,才能上传作品资源');
  386. }
  387. },
  388. };
  389. </script>
  390. <style lang="scss">
  391. @import "../../assets/css/common.css";
  392. @import "../../assets/css/public.css";
  393. .work-title {
  394. width: 960px;
  395. line-height: 37px;
  396. padding: 5px 0 25px 0;
  397. margin-left: -80px;
  398. font-size: 26px;
  399. font-family: PingFangSC, PingFangSC-Medium;
  400. font-weight: 500;
  401. text-align: center;
  402. color: #1d2a3a;
  403. border-bottom: 1px solid rgba(0,0,0,0.06);
  404. }
  405. .editor {
  406. position: relative;
  407. padding: 20px 100px;
  408. width: 1000px;
  409. background: #fff;
  410. .title,
  411. .sub-title {
  412. .el-input__inner {
  413. padding: 0;
  414. border: 0;
  415. border-radius: 0;
  416. }
  417. }
  418. .title {
  419. margin: 10px auto 20px;
  420. font-size: 28px;
  421. font-family: PingFangSC-Medium;
  422. font-weight: 500;
  423. color: rgba(29, 42, 58, 1);
  424. line-height: 40px;
  425. }
  426. ._title {
  427. font-size: 15px !important;
  428. margin: 0 !important;
  429. border-bottom: 1px solid #ddd;
  430. }
  431. .sub-title {
  432. margin-bottom: 28px;
  433. min-height: 18px;
  434. font-size: 14px;
  435. font-family: PingFangSC-Regular;
  436. font-weight: 400;
  437. color: rgba(145, 154, 167, 1);
  438. line-height: 18px;
  439. border: 0;
  440. .el-textarea__inner {
  441. height: 18px;
  442. line-height: 18px;
  443. border: 0;
  444. padding-left: 0;
  445. }
  446. }
  447. .label {
  448. margin: 20px auto 10px;
  449. font-size: 13px;
  450. font-family: PingFangSC-Medium;
  451. font-weight: 500;
  452. color: rgba(25, 34, 46, 1);
  453. line-height: 18px;
  454. }
  455. .ql-toolbar {
  456. border-width: 1px 0 0 0 !important;
  457. }
  458. .quill-editor {
  459. height: 450px;
  460. border-left: 0 !important;
  461. border-right: 0 !important;
  462. font-size: 14px;
  463. line-height: 25px;
  464. }
  465. .ql-snow.ql-toolbar::after {
  466. display: inline-block;
  467. }
  468. .class {
  469. width: 320px;
  470. }
  471. .tags {
  472. width: 560px;
  473. }
  474. footer {
  475. margin: 40px 0;
  476. /*button {*/
  477. /* width: 100px;*/
  478. /* height: 40px;*/
  479. /* border-radius: 0;*/
  480. /*}*/
  481. }
  482. strong {
  483. font-weight: 800 !important;
  484. }
  485. em {
  486. font-style: italic !important;
  487. }
  488. }
  489. .uploadInfo {
  490. display: flex;
  491. padding-left: 30px;
  492. align-items: center;
  493. .left {
  494. width: 150px;
  495. height: 180px;
  496. flex-shrink: 0;
  497. overflow: hidden;
  498. position: relative;
  499. background: #fff;
  500. .el-icon-delete {
  501. display: none;
  502. }
  503. .avatar-uploader .el-upload {
  504. width: 150px;
  505. height: 150px;
  506. border: 1px dashed #dce1e8;
  507. border-radius: 6px;
  508. cursor: pointer;
  509. position: relative;
  510. overflow: hidden;
  511. img {
  512. width: 100%;
  513. height: auto;
  514. object-fit: contain;
  515. object-position: top left;
  516. }
  517. }
  518. .avatar-uploader .el-upload:hover {
  519. border-color: #409eff;
  520. .el-icon-plus {
  521. color: #409eff
  522. }
  523. .el-p-upload {
  524. color: #409eff
  525. }
  526. .el-icon-delete {
  527. display: block;
  528. }
  529. }
  530. .avatar-uploader-icon {
  531. /*position: absolute;*/
  532. /*top: 0;*/
  533. /*left: 0;*/
  534. font-size: 44px;
  535. color: #dce1e8;;
  536. /*width: 150px;*/
  537. /*height: 150px;*/
  538. /*line-height: 140px;*/
  539. text-align: center;
  540. }
  541. .el-p-upload {
  542. color: #dce1e8
  543. }
  544. .avatar {
  545. width: 180px;
  546. height: 140px;
  547. display: block;
  548. }
  549. .title {
  550. position: absolute;
  551. left: 50%;
  552. bottom: 40px;
  553. transform: translateX(-50%);
  554. font-size: 13px;
  555. font-weight: 500;
  556. color: #dce1e8;
  557. line-height: 18px;
  558. text-decoration: underline;
  559. }
  560. }
  561. .right {
  562. margin-left: 18px;
  563. height: 34px;
  564. p {
  565. font-size: 12px;
  566. font-weight: 400;
  567. color: rgba(145, 154, 167, 1);
  568. line-height: 17px;
  569. }
  570. }
  571. }
  572. .btn-save {
  573. width: 20vw;
  574. border-radius: 5px;
  575. }
  576. .work-field {
  577. width: 100%;
  578. margin-top: 20px;
  579. display: flex;
  580. flex-direction: column;
  581. .work-label {
  582. margin-bottom: 5px;
  583. line-height: 20px;
  584. font-size: 14px;
  585. font-family: PingFangSC, PingFangSC-Medium;
  586. font-weight: 500;
  587. color: #19222e;
  588. }
  589. .upload-tips {
  590. line-height: 20px;
  591. margin-left: 10px;
  592. font-size: 14px;
  593. font-weight: 400;
  594. color: #999999;
  595. }
  596. .upload-btn {
  597. width: 160px;
  598. height: 40px;
  599. line-height: 40px;
  600. border: 1px solid #308eff;
  601. border-radius: 6px;
  602. font-size: 14px;
  603. font-family: PingFangSC, PingFangSC-Medium;
  604. font-weight: 500;
  605. text-align: center;
  606. color: #308eff;
  607. }
  608. .work-cate-type {
  609. width: 100%;
  610. height: 40px;
  611. display: flex;
  612. align-items: center;
  613. .work-cate-cascader {
  614. width: 315px;
  615. margin-right: 30px;
  616. }
  617. }
  618. .work-price-wrapper {
  619. display: flex;
  620. align-items: center;
  621. .work-price-input {
  622. width: 315px;
  623. }
  624. span {
  625. margin-left: 8px;
  626. font-size: 14px;
  627. font-family: PingFangSC, PingFangSC-Medium;
  628. font-weight: 500;
  629. color: #19222e;
  630. }
  631. }
  632. }
  633. .custom-radio {
  634. .el-radio__inner {
  635. width: 20px;
  636. height: 20px;
  637. border: none;
  638. border-radius: 0;
  639. background: url("~@/assets/img/common/custom-radio.png") no-repeat !important;
  640. &:after {
  641. content: none;
  642. }
  643. }
  644. .is-checked {
  645. .el-radio__inner {
  646. background: url("~@/assets/img/common/custom-radio-checked.png") no-repeat !important;
  647. }
  648. }
  649. }
  650. </style>
  651. <style>
  652. input::-webkit-outer-spin-button,
  653. input::-webkit-inner-spin-button {
  654. -webkit-appearance: none !important;
  655. }
  656. input[type="number"]{
  657. -moz-appearance: textfield !important;
  658. }
  659. </style>