editor.vue 19 KB

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