touGao.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. <template>
  2. <view class="box3">
  3. <u-navbar :autoBack="true" title="投稿" bgColor="rgba(255,255,255,0)" :placeholder="true" titleStyle="font-weight:bold;color:#121212"></u-navbar>
  4. <view class="nav_fabu">
  5. <view class="nav_left" @click="releaseBtn(0)">
  6. <view class="left_icon"><uni-icons type="compose" size="20" color=" #ffffff"></uni-icons></view>
  7. <text>发文章</text>
  8. </view>
  9. <view class="nav_right" @click="releaseBtn(1)">
  10. <view class="left_icon" style="background-color: #4e7198"><uni-icons type="videocam" size="20" color=" #ffffff"></uni-icons></view>
  11. <text>发视频</text>
  12. </view>
  13. <view class="uptriangle" :class="{ uptriangle_active: releaseTab == 1, uptriangle: releaseTab == 0 }"></view>
  14. </view>
  15. <!-- 上传发布组件 -->
  16. <view style="width: 92%; margin: auto; margin-top: 30rpx">
  17. <u--input v-model.trim="titleVal" customStyle="background-color: #ffffff;height: 80rpx;" placeholder="请填写标题" border="surround" clearable></u--input>
  18. </view>
  19. <view class="" style="width: 92%; margin: auto; margin-top: 30rpx">
  20. <u-search
  21. searchIconSize="0"
  22. height="80rpx"
  23. :showAction="false"
  24. bgColor="#ffffff"
  25. :placeholder="searchVal ? searchVal : '关联文物'"
  26. v-model="val"
  27. shape="square"
  28. @change="searchBtn"
  29. :actionStyle="{ color: '#985741', fontSize: '30rpx', fontWeight: 'bold' }"
  30. ></u-search>
  31. </view>
  32. <!-- 搜索的文物 -->
  33. <u-transition :show="searchList.length > 0">
  34. <scroll-view v-if="searchList.length > 0" class="search_box" scroll-y="true" @scrolltolower="LoadMore">
  35. <view>
  36. <view @click="searchItem(item)" class="item_tit" v-for="item in searchList" :key="item.id">
  37. {{ item.title }}
  38. </view>
  39. </view>
  40. </scroll-view>
  41. </u-transition>
  42. <view class="box">
  43. <!-- 上传照片 -->
  44. <view style="margin-left: 36rpx" v-if="releaseTab == 0">
  45. <view class="sc_box">
  46. <text class="sc_tp">请上传图片</text>
  47. <text class="sc_tp">{{ uploadNumber + '/' + 9 }}</text>
  48. </view>
  49. <u-upload
  50. width="200rpx"
  51. height="200rpx"
  52. :maxCount="9"
  53. imageMode="aspectFit"
  54. :deletable="true"
  55. :fileList="fileList1"
  56. @afterRead="afterRead"
  57. @delete="deletePic"
  58. name="1"
  59. multiple
  60. ></u-upload>
  61. </view>
  62. <!-- 上传视频 -->
  63. <view style="margin-left: 26rpx" v-if="releaseTab == 1">
  64. <view class="sc_box">
  65. <text class="sc_tp">请上传视频</text>
  66. </view>
  67. <u-upload
  68. width="200rpx"
  69. height="200rpx"
  70. :fileList="fileList2"
  71. @afterRead="afterRead"
  72. @delete="deletePic"
  73. name="2"
  74. multiple
  75. :maxCount="10"
  76. accept="video"
  77. ></u-upload>
  78. </view>
  79. <view class="banxin" style="background-color: #ffffff; margin-top: 20rpx">
  80. <!-- <u--textarea v-model.trim="textVal" placeholder="请输入内容"></u--textarea> -->
  81. <view class="" style="height: 400rpx">
  82. <sp-editor
  83. :toolbar-config="{
  84. excludeKeys: ['direction', 'date', 'lineHeight', 'letterSpacing', 'listCheck'],
  85. iconSize: '18px'
  86. }"
  87. @input="inputOver"
  88. @upinImage="upinImage"
  89. @addLink="addLink"
  90. @exportHtml="exportHtml"
  91. ></sp-editor>
  92. </view>
  93. </view>
  94. <!-- 分区 -->
  95. <u-popup :show="showTanCeng" mode="bottom" @close="close" bgColor="#efefef">
  96. <view class="show_box">
  97. <view class="" style="display: flex; justify-content: space-between">
  98. <text @click="showTanCeng = false">取消</text>
  99. <text @click="showTanCeng = false" class="box_ok">确认</text>
  100. </view>
  101. <view class="box_fenqu" @click="show = true">
  102. <text>选择投稿类型</text>
  103. <view style="display: flex">
  104. <text style="color: #999999; font-size: 28rpx">{{ typeName }}</text>
  105. <uni-icons color="#999999" type="forward" size="20"></uni-icons>
  106. </view>
  107. </view>
  108. <!-- 添加标签 -->
  109. <view class="box_tj">
  110. <text style="color: #999999; font-size: 28rpx">选择内容类型</text>
  111. <view class="tag_box">
  112. <view class="" v-for="(item, index) in radios" :key="index">
  113. <u-tag size="mini" :text="item.name" :plain="!item.checked" shape="circle" type="warning" :name="index" @click="radioClick"></u-tag>
  114. </view>
  115. </view>
  116. </view>
  117. <u-picker
  118. title="选择投稿类型"
  119. :show="show"
  120. @close="show = false"
  121. ref="uPicker"
  122. @cancel="show = false"
  123. keyName="name"
  124. :closeOnClickOverlay="true"
  125. :columns="columns"
  126. @confirm="confirm"
  127. ></u-picker>
  128. </view>
  129. </u-popup>
  130. <view class="" style="background-color: #efefef; height: 20rpx; width: 100%"><!-- 分割背景 --></view>
  131. <view class="fq_box" @click="fenquBtn">
  132. <text>选择投稿类型</text>
  133. <view class="bq_box">
  134. <u-tag size="mini" shape="circle" text="文物" type="warning"></u-tag>
  135. <u-tag size="mini" shape="circle" text="非遗" type="success"></u-tag>
  136. <u-tag size="mini" shape="circle" text="民俗" type="error"></u-tag>
  137. <u-icon name="arrow-right" color="#666666" size="16"></u-icon>
  138. </view>
  139. </view>
  140. <!-- 评论 -->
  141. <view class="" style="background-color: #efefef; height: 20rpx; width: 100%"></view>
  142. <view class="queren" @click="isOk">确认发布</view>
  143. </view>
  144. </view>
  145. </template>
  146. <script>
  147. let that;
  148. export default {
  149. data() {
  150. return {
  151. val: '',
  152. cr_id: '' /* 文物id */,
  153. searchVal: '',
  154. searchList: [] /* 搜索的数组 */,
  155. isLoading: false,
  156. page: 1,
  157. prevSearchVal: '',
  158. releaseTab: 0,
  159. radios: [
  160. {
  161. name: '文章',
  162. id: 1,
  163. checked: true
  164. },
  165. {
  166. name: '视频',
  167. id: 2,
  168. checked: false
  169. },
  170. {
  171. name: '音频',
  172. id: 3,
  173. checked: false
  174. },
  175. {
  176. name: '相册',
  177. id: 4,
  178. checked: false
  179. }
  180. ],
  181. model_id: '' /* 投稿模型id */,
  182. typeId: 1 /* 投稿内容类型id */,
  183. main_body_column_id: '' /* 投稿栏目id */,
  184. typeName: '' /* 选中的类型 */,
  185. closeTag: true,
  186. showTanCeng: false,
  187. show: false,
  188. columns: [
  189. [
  190. { name: '我与文物的故事', id: 73 },
  191. { name: '价值挖掘', id: 72 }
  192. ]
  193. ],
  194. titleVal: '',
  195. textVal: '',
  196. // 上传的图片
  197. fileList1: [],
  198. // 上传的视频
  199. fileList2: []
  200. };
  201. },
  202. onLoad() {
  203. that = this;
  204. },
  205. computed: {
  206. uploadNumber() {
  207. return this.fileList1.length;
  208. }
  209. },
  210. methods: {
  211. // 搜索
  212. searchBtn() {
  213. if (this.val) {
  214. // 只有在搜索词变化时重置page为1
  215. if (this.prevSearchVal !== this.val) {
  216. this.prevSearchVal = this.val; // 更新prevSearchVal为当前搜索词
  217. this.page = 1; // 当搜索词变化时重置page
  218. this.searchList = []; // 清空已有搜索结果
  219. }
  220. this.$api.getContentList(
  221. {
  222. main_body_id: 1,
  223. model_id: 1,
  224. keywords: this.val,
  225. page: this.page,
  226. pageSize: '10'
  227. },
  228. function (res) {
  229. that.searchList = [...that.searchList, ...res.data];
  230. }
  231. );
  232. } else {
  233. this.searchList = [];
  234. }
  235. },
  236. // 搜索的每项
  237. searchItem(item) {
  238. // console.log(item, 666666666);
  239. this.searchVal = item.title;
  240. this.cr_id = item.id;
  241. this.val = '';
  242. this.searchList = [];
  243. },
  244. // 下滑加载
  245. LoadMore() {
  246. this.page++;
  247. this.searchBtn();
  248. },
  249. releaseBtn(i) {
  250. this.releaseTab = i;
  251. },
  252. fenquBtn() {
  253. // this.show = true;
  254. this.showTanCeng = true;
  255. },
  256. confirm(e) {
  257. console.log('confirm', e.value);
  258. this.model_id = e.value[0].model_id;
  259. this.main_body_column_id = e.value[0].id;
  260. this.typeName = e.value[0].name;
  261. this.show = false;
  262. },
  263. // 删除图片
  264. deletePic(event) {
  265. console.log(event, 'event');
  266. this[`fileList${event.name}`].splice(event.index, 1);
  267. },
  268. // 新增图片
  269. async afterRead(event) {
  270. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  271. let lists = [].concat(event.file);
  272. let fileListLen = this[`fileList${event.name}`].length;
  273. lists.map((item) => {
  274. this[`fileList${event.name}`].push({
  275. ...item,
  276. status: 'uploading',
  277. message: '上传中'
  278. });
  279. });
  280. for (let i = 0; i < lists.length; i++) {
  281. const result = await this.uploadFilePromise(lists[i].url);
  282. let item = this[`fileList${event.name}`][fileListLen];
  283. this[`fileList${event.name}`].splice(
  284. fileListLen,
  285. 1,
  286. Object.assign(item, {
  287. status: 'success',
  288. message: '',
  289. url: result
  290. })
  291. );
  292. fileListLen++;
  293. }
  294. console.log(this.fileList1, 'uuuu');
  295. },
  296. uploadFilePromise(url) {
  297. return new Promise((resolve, reject) => {
  298. let userToken = '';
  299. let auth = this.$db.get('auth');
  300. userToken = auth.token;
  301. let a = uni.uploadFile({
  302. url: this.$config.baseUrl + 'api/common/upload?token=' + userToken, // 仅为示例,非真实的接口地址
  303. filePath: url,
  304. name: 'file',
  305. formData: {},
  306. success: (res) => {
  307. setTimeout(() => {
  308. console.log(res);
  309. resolve(JSON.parse(res.data).data.fullurl);
  310. }, 1000);
  311. }
  312. });
  313. });
  314. },
  315. radioClick(name) {
  316. this.radios.map((item, index) => {
  317. item.checked = index === name ? true : false;
  318. });
  319. this.typeId = this.radios[name].id;
  320. },
  321. // 投稿
  322. isOk() {
  323. let titleIsEmpty = this.titleVal === '';
  324. let textIsEmpty = this.textVal === '';
  325. // 先检查标题和内容是否为空
  326. if (titleIsEmpty) {
  327. that.$common.errorToShow('请填写投稿标题');
  328. return false; // 遇到错误时提前返回,避免后续条件的判断
  329. }
  330. if (textIsEmpty) {
  331. that.$common.errorToShow('请输入投稿内容');
  332. return false;
  333. }
  334. // 再检查模型ID、类型ID和栏目ID
  335. if (this.model_id === '' || this.main_body_column_id === '') {
  336. that.$common.errorToShow('请选择投稿类型');
  337. return false;
  338. }
  339. let image = '';
  340. let images = '';
  341. if (this.fileList1.length !== 0) {
  342. image = this.fileList1[0].url;
  343. images = this.fileList1.map((itme) => itme.url).join(',');
  344. }
  345. // 如果typeId是必须选择的,这里也要进行验证
  346. if (this.typeId === '') {
  347. that.$common.errorToShow('请选择内容类型');
  348. return false;
  349. } else {
  350. this.$api.contribute(
  351. {
  352. main_body_id: 1,
  353. model_id: 1,
  354. main_body_column_id: this.main_body_column_id,
  355. title: this.titleVal,
  356. type: this.typeId,
  357. content: this.textVal,
  358. cr_id: this.cr_id,
  359. image: image,
  360. images: images
  361. },
  362. function (res) {
  363. if (res.code == 1) {
  364. that.$common.successToShow('投稿成功');
  365. setTimeout(() => {
  366. uni.redirectTo({
  367. url: '/user_fenbao/myTouGao/myTouGao'
  368. });
  369. }, 1000);
  370. } else {
  371. that.$common.errorToShow('投稿失败请稍后再试');
  372. // console.log(that.fileList1, 6666);
  373. }
  374. }
  375. );
  376. }
  377. },
  378. close() {
  379. this.showTanCeng = false;
  380. // console.log('close');
  381. },
  382. // 富文本相关
  383. inputOver(e) {
  384. // 可以在此处获取到编辑器已编辑的内容
  385. console.log('==== inputOver :', e);
  386. this.textVal = e.html;
  387. },
  388. upinImage(tempFiles, editorCtx) {
  389. that.$common.errorToShow('请在上方上传图片');
  390. // uni.chooseImage({
  391. // count: 1,
  392. // sizeType: ['compressed'],
  393. // sourceType: ['album'],
  394. // success: (res) => {
  395. // console.log('chooseImage', res.tempFilePaths);
  396. // var imageFileSrc = res.tempFilePaths;
  397. // let userToken = '';
  398. // let auth = this.$db.get('auth');
  399. // userToken = auth.token;
  400. // uni.uploadFile({
  401. // url: this.$config.baseUrl + 'api/common/upload?token=' + userToken, // 仅为示例,非真实的接口地址
  402. // filePath: imageFileSrc[0],
  403. // name: 'file',
  404. // formData: {
  405. // Accept: 'application/json',
  406. // 'Content-Type': 'multipart/form-data',
  407. // token: userToken
  408. // },
  409. // success: (uploadFileRes) => {
  410. // console.log(JSON.parse(uploadFileRes.data), 9999);
  411. // var dataimg = JSON.parse(uploadFileRes.data);
  412. // this.imageSrc = dataimg.data.fullurl;
  413. // this.imagepath = dataimg.data.url;
  414. // }
  415. // });
  416. // },
  417. // fail: (err) => {
  418. // console.log('chooseImage fail', err);
  419. // }
  420. // });
  421. },
  422. /**
  423. * 导出 - toolbar需要开启export工具
  424. * @param {string} e 导出的html内容
  425. */
  426. exportHtml(e) {
  427. uni.navigateTo({
  428. url: '/pages/personInfo/personalInfo',
  429. success(res) {
  430. // 传至导出页面解析即可
  431. res.eventChannel.emit('e-transmit-html', {
  432. data: e
  433. });
  434. }
  435. });
  436. },
  437. /**
  438. * 添加超链接
  439. * @param {Object} e { text: '链接描述', href: '链接地址' }
  440. */
  441. addLink(e) {
  442. console.log('==== addLink :', e);
  443. }
  444. }
  445. };
  446. </script>
  447. <style>
  448. .box3 {
  449. width: 100%;
  450. padding-bottom: 50rpx;
  451. background-image: url('https://huli-app.wenlvti.net/app_static/WenWuGuanJia/image/xbg_2.png');
  452. background-size: 100% 100%;
  453. background-attachment: fixed;
  454. background-repeat: repeat-y;
  455. height: auto;
  456. }
  457. .uptriangle {
  458. position: absolute;
  459. top: 120rpx;
  460. left: 170rpx;
  461. width: 0px;
  462. height: 0px;
  463. border: 30rpx solid transparent;
  464. border-top-color: #ca5642;
  465. }
  466. .uptriangle_active {
  467. position: absolute;
  468. top: 120rpx;
  469. left: 510rpx;
  470. width: 0px;
  471. height: 0px;
  472. border: 30rpx solid transparent;
  473. border-top-color: #ca5642;
  474. }
  475. .banxin {
  476. margin: 0 32rpx 0 32rpx;
  477. }
  478. .u-upload__button.data-v-69e2a36e {
  479. background-color: #efefef !important;
  480. }
  481. .u-upload__deletable.data-v-69e2a36e {
  482. width: 35rpx !important;
  483. height: 35rpx !important;
  484. }
  485. .u-transition {
  486. margin-right: 12rpx;
  487. }
  488. .tag_box {
  489. display: flex;
  490. margin-top: 20rpx;
  491. }
  492. .nav_fabu {
  493. position: relative;
  494. display: flex;
  495. justify-content: space-evenly;
  496. background-color: #ca5642;
  497. }
  498. .nav_left {
  499. display: flex;
  500. justify-content: start;
  501. align-items: center;
  502. width: 282rpx;
  503. height: 123rpx;
  504. font-size: 32rpx;
  505. background: #f4f4f9;
  506. border: 6px solid #ca5642;
  507. border-radius: 20rpx;
  508. }
  509. .left_icon {
  510. width: 50rpx;
  511. height: 50rpx;
  512. text-align: center;
  513. line-height: 50rpx;
  514. border-radius: 50%;
  515. margin-left: 50rpx;
  516. background-color: #ca5642;
  517. }
  518. .nav_right {
  519. display: flex;
  520. justify-content: start;
  521. align-items: center;
  522. width: 282rpx;
  523. height: 123rpx;
  524. font-size: 32rpx;
  525. background: #f4f4f9;
  526. border: 6px solid #ca5642;
  527. border-radius: 20rpx;
  528. }
  529. .right_icon {
  530. width: 50rpx;
  531. height: 50rpx;
  532. margin-left: 50rpx;
  533. border-radius: 50%;
  534. background-color: #4e7198;
  535. }
  536. .sc_box {
  537. display: flex;
  538. align-items: center;
  539. margin: 40rpx 55rpx 40rpx 10rpx;
  540. border-bottom: 1px #dedede solid;
  541. height: 60rpx;
  542. }
  543. .sc_tp {
  544. font-size: 30rpx;
  545. color: #000000;
  546. }
  547. .fq_box {
  548. display: flex;
  549. justify-content: space-between;
  550. margin: 0 32rpx 0 50rpx;
  551. height: 105rpx;
  552. align-items: center;
  553. }
  554. .box {
  555. /* background-color: #ffffff; */
  556. /* padding-top: 20rpx;
  557. padding-bottom: 30rpx; */
  558. }
  559. .bq_box {
  560. display: flex;
  561. align-items: center;
  562. }
  563. .pl_box {
  564. display: flex;
  565. justify-content: space-between;
  566. margin: 0 32rpx 0 32rpx;
  567. height: 105rpx;
  568. align-items: center;
  569. }
  570. .show_box {
  571. width: 100%;
  572. height: 500rpx;
  573. padding: 20rpx;
  574. }
  575. .queren {
  576. height: 80rpx;
  577. background-color: #ca5642;
  578. border-radius: 35rpx;
  579. font-size: 30rpx;
  580. color: #ffffff;
  581. text-align: center;
  582. line-height: 80rpx;
  583. margin: 0 32rpx 0 32rpx;
  584. }
  585. .box_ok {
  586. line-height: 50rpx;
  587. text-align: center;
  588. color: #ffffff;
  589. width: 93rpx;
  590. height: 52rpx;
  591. background: #ca5642;
  592. border-radius: 26rpx;
  593. }
  594. .box_fenqu {
  595. display: flex;
  596. justify-content: space-between;
  597. align-items: center;
  598. border-radius: 20rpx;
  599. margin-top: 20rpx;
  600. height: 105rpx;
  601. background-color: #ffffff;
  602. font-size: 30rpx;
  603. padding: 20rpx;
  604. }
  605. .box_tj {
  606. height: 300rpx;
  607. border-radius: 20rpx;
  608. background-color: #ffffff;
  609. margin-top: 20rpx;
  610. padding: 20rpx;
  611. }
  612. .search_box {
  613. width: 90%;
  614. position: absolute;
  615. height: 200px;
  616. z-index: 39;
  617. left: 32rpx;
  618. padding: 40rpx;
  619. background-color: #f7dfc0;
  620. }
  621. .item_tit {
  622. line-height: 50rpx;
  623. font-size: 30rpx;
  624. }
  625. </style>