editor.vue 20 KB

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