editor.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  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 = res.data.price > 0 ? 2 : 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. this.wid = res.data.wid || ''
  304. // setTimeout(() => {
  305. // self.$router.push({
  306. // path: '/sign/new',
  307. // query: { from: 'works' }
  308. // })
  309. // }, 1200);
  310. } else {
  311. this.$message.error("添加作品失败,请重试");
  312. }
  313. this.isPublishing = false;
  314. });
  315. }
  316. },
  317. /**
  318. * 输入合法性检查
  319. * @return {{msg: string, success: boolean}}
  320. */
  321. publishValidCheck() {
  322. if (!this.workName) {
  323. return {success: false, msg: "请输入作品名称"};
  324. }
  325. if (this.workName.length < 2) {
  326. return {success: false, msg: "作品名称不可少于2字符"};
  327. }
  328. if (this.workName.length > 50) {
  329. return {success: false, msg: "作品名称不可超过50字符,请删减"};
  330. }
  331. if (!this.content) {
  332. return {success: false, msg: "请输入作品描述"};
  333. }
  334. if (this.content.length < 60) {
  335. return {success: false, msg: "作品描述不可少于60字符"};
  336. }
  337. if (this.content.length > 10000) {
  338. return {success: false, msg: "作品描述不可大于10000字符,请删减"};
  339. }
  340. if (this.workImages.length < 2) {
  341. return {success: false, msg: "至少上传2张作品截图"};
  342. }
  343. if (this.selectedWorkCate.length !== 2 || (!this.selectedWorkCate[0] || !this.selectedWorkCate[1])) {
  344. return {success: false, msg: "请选择作品分类"};
  345. }
  346. if (this.workType === 2) {
  347. if (this.price <= 0) {
  348. return {success: false, msg: "请输入大于0的资源价格"};
  349. }
  350. if (String(this.price).indexOf('.') > -1 &&
  351. String(this.price).length - String(this.price).indexOf('.') - 1 > 2) {
  352. return {success: false, msg: "资源价格最多保留两位小数"};
  353. }
  354. }
  355. return {success: true, msg: ""}
  356. },
  357. cancel() {
  358. this.$router.back();
  359. },
  360. handleChange(val) {
  361. this.content = val;
  362. },
  363. handleDeleteFile() {
  364. this.cover_url = "";
  365. },
  366. handleFileChange(file) {
  367. console.log(file);
  368. if (file.size / 1024 > 2048) {
  369. this.$message.error("图片大小不得超过2M,请重新选择");
  370. return false;
  371. }
  372. const formData = new FormData();
  373. formData.append("target", '{ "type": 3 }');
  374. formData.append("id", "WU_FILE_0");
  375. formData.append("name", file.name);
  376. formData.append("type", file.type);
  377. formData.append("lastModifiedDate", file.lastModifiedDate);
  378. formData.append("size", file.size);
  379. formData.append("file", file);
  380. this.$axios.$post(`/file/proxyUpload`, formData, {headers: {"Content-Type": "multipart/form-data"}}).then(res => {
  381. this.cover_url = (res.data && res.data.url) || "";
  382. this.fileList = [
  383. {
  384. name: "file.name",
  385. url: this.cover_url
  386. }
  387. ];
  388. });
  389. },
  390. workNameBlur(e) {
  391. this.workName = this.workName.replace(/[&|\*|#|\\]/g, "");
  392. },
  393. handleSuccess(response, file, fileList) {
  394. },
  395. showUploadTips () {
  396. this.$message.info('先保存项目作品,才能上传作品资源');
  397. }
  398. },
  399. };
  400. </script>
  401. <style lang="scss">
  402. @import "../../assets/css/common.css";
  403. @import "../../assets/css/public.css";
  404. .work-title {
  405. width: 960px;
  406. line-height: 37px;
  407. padding: 5px 0 25px 0;
  408. margin-left: -80px;
  409. font-size: 26px;
  410. font-family: PingFangSC, PingFangSC-Medium;
  411. font-weight: 500;
  412. text-align: center;
  413. color: #1d2a3a;
  414. border-bottom: 1px solid rgba(0,0,0,0.06);
  415. }
  416. .editor {
  417. position: relative;
  418. padding: 20px 100px;
  419. width: 1000px;
  420. background: #fff;
  421. .title,
  422. .sub-title {
  423. .el-input__inner {
  424. padding: 0;
  425. border: 0;
  426. border-radius: 0;
  427. }
  428. }
  429. .title {
  430. margin: 10px auto 20px;
  431. font-size: 28px;
  432. font-family: PingFangSC-Medium;
  433. font-weight: 500;
  434. color: rgba(29, 42, 58, 1);
  435. line-height: 40px;
  436. }
  437. ._title {
  438. font-size: 15px !important;
  439. margin: 0 !important;
  440. border-bottom: 1px solid #ddd;
  441. }
  442. .sub-title {
  443. margin-bottom: 28px;
  444. min-height: 18px;
  445. font-size: 14px;
  446. font-family: PingFangSC-Regular;
  447. font-weight: 400;
  448. color: rgba(145, 154, 167, 1);
  449. line-height: 18px;
  450. border: 0;
  451. .el-textarea__inner {
  452. height: 18px;
  453. line-height: 18px;
  454. border: 0;
  455. padding-left: 0;
  456. }
  457. }
  458. .label {
  459. margin: 20px auto 10px;
  460. font-size: 13px;
  461. font-family: PingFangSC-Medium;
  462. font-weight: 500;
  463. color: rgba(25, 34, 46, 1);
  464. line-height: 18px;
  465. }
  466. .ql-toolbar {
  467. border-width: 1px 0 0 0 !important;
  468. }
  469. .quill-editor {
  470. height: 450px;
  471. border-left: 0 !important;
  472. border-right: 0 !important;
  473. font-size: 14px;
  474. line-height: 25px;
  475. }
  476. .ql-snow.ql-toolbar::after {
  477. display: inline-block;
  478. }
  479. .class {
  480. width: 320px;
  481. }
  482. .tags {
  483. width: 560px;
  484. }
  485. footer {
  486. margin: 40px 0;
  487. /*button {*/
  488. /* width: 100px;*/
  489. /* height: 40px;*/
  490. /* border-radius: 0;*/
  491. /*}*/
  492. }
  493. strong {
  494. font-weight: 800 !important;
  495. }
  496. em {
  497. font-style: italic !important;
  498. }
  499. }
  500. .uploadInfo {
  501. display: flex;
  502. padding-left: 30px;
  503. align-items: center;
  504. .left {
  505. width: 150px;
  506. height: 180px;
  507. flex-shrink: 0;
  508. overflow: hidden;
  509. position: relative;
  510. background: #fff;
  511. .el-icon-delete {
  512. display: none;
  513. }
  514. .avatar-uploader .el-upload {
  515. width: 150px;
  516. height: 150px;
  517. border: 1px dashed #dce1e8;
  518. border-radius: 6px;
  519. cursor: pointer;
  520. position: relative;
  521. overflow: hidden;
  522. img {
  523. width: 100%;
  524. height: auto;
  525. object-fit: contain;
  526. object-position: top left;
  527. }
  528. }
  529. .avatar-uploader .el-upload:hover {
  530. border-color: #409eff;
  531. .el-icon-plus {
  532. color: #409eff
  533. }
  534. .el-p-upload {
  535. color: #409eff
  536. }
  537. .el-icon-delete {
  538. display: block;
  539. }
  540. }
  541. .avatar-uploader-icon {
  542. /*position: absolute;*/
  543. /*top: 0;*/
  544. /*left: 0;*/
  545. font-size: 44px;
  546. color: #dce1e8;;
  547. /*width: 150px;*/
  548. /*height: 150px;*/
  549. /*line-height: 140px;*/
  550. text-align: center;
  551. }
  552. .el-p-upload {
  553. color: #dce1e8
  554. }
  555. .avatar {
  556. width: 180px;
  557. height: 140px;
  558. display: block;
  559. }
  560. .title {
  561. position: absolute;
  562. left: 50%;
  563. bottom: 40px;
  564. transform: translateX(-50%);
  565. font-size: 13px;
  566. font-weight: 500;
  567. color: #dce1e8;
  568. line-height: 18px;
  569. text-decoration: underline;
  570. }
  571. }
  572. .right {
  573. margin-left: 18px;
  574. height: 34px;
  575. p {
  576. font-size: 12px;
  577. font-weight: 400;
  578. color: rgba(145, 154, 167, 1);
  579. line-height: 17px;
  580. }
  581. }
  582. }
  583. .btn-save {
  584. width: 20vw;
  585. border-radius: 5px;
  586. }
  587. .work-field {
  588. width: 100%;
  589. margin-top: 20px;
  590. display: flex;
  591. flex-direction: column;
  592. .work-label {
  593. margin-bottom: 5px;
  594. line-height: 20px;
  595. font-size: 14px;
  596. font-family: PingFangSC, PingFangSC-Medium;
  597. font-weight: 500;
  598. color: #19222e;
  599. }
  600. .upload-tips {
  601. line-height: 20px;
  602. margin-left: 10px;
  603. font-size: 14px;
  604. font-weight: 400;
  605. color: #999999;
  606. }
  607. .upload-btn {
  608. width: 160px;
  609. height: 40px;
  610. line-height: 40px;
  611. border: 1px solid #308eff;
  612. border-radius: 6px;
  613. font-size: 14px;
  614. font-family: PingFangSC, PingFangSC-Medium;
  615. font-weight: 500;
  616. text-align: center;
  617. color: #308eff;
  618. }
  619. .work-cate-type {
  620. width: 100%;
  621. height: 40px;
  622. display: flex;
  623. align-items: center;
  624. .work-cate-cascader {
  625. width: 315px;
  626. margin-right: 30px;
  627. }
  628. }
  629. .work-price-wrapper {
  630. display: flex;
  631. align-items: center;
  632. .work-price-input {
  633. width: 315px;
  634. }
  635. span {
  636. margin-left: 8px;
  637. font-size: 14px;
  638. font-family: PingFangSC, PingFangSC-Medium;
  639. font-weight: 500;
  640. color: #19222e;
  641. }
  642. }
  643. }
  644. .custom-radio {
  645. .el-radio__inner {
  646. width: 20px;
  647. height: 20px;
  648. border: none;
  649. border-radius: 0;
  650. background: url("~@/assets/img/common/custom-radio.png") no-repeat !important;
  651. &:after {
  652. content: none;
  653. }
  654. }
  655. .is-checked {
  656. .el-radio__inner {
  657. background: url("~@/assets/img/common/custom-radio-checked.png") no-repeat !important;
  658. }
  659. }
  660. }
  661. </style>
  662. <style>
  663. input::-webkit-outer-spin-button,
  664. input::-webkit-inner-spin-button {
  665. -webkit-appearance: none !important;
  666. }
  667. input[type="number"]{
  668. -moz-appearance: textfield !important;
  669. }
  670. </style>