editor.vue 20 KB

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