touGao.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. <template>
  2. <view class="body" style="background-color: #efefef">
  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="margin: 20rpx 0 20rpx 0">
  17. <u--input v-model.trim="titleVal" customStyle="background-color: #ffffff;height: 105rpx;" placeholder="请填写标题" border="surround" clearable></u--input>
  18. </view>
  19. <view class="box">
  20. <!-- 上传照片 -->
  21. <view style="margin-left: 56rpx" v-if="releaseTab == 0">
  22. <view class="sc_box">
  23. <text class="sc_tp">请上传图片</text>
  24. <text class="sc_tp">{{ uploadNumber + '/' + 9 }}</text>
  25. </view>
  26. <u-upload
  27. width="200rpx"
  28. height="200rpx"
  29. :maxCount="9"
  30. :deletable="true"
  31. :fileList="fileList1"
  32. @afterRead="afterRead"
  33. @delete="deletePic"
  34. name="1"
  35. multiple
  36. ></u-upload>
  37. </view>
  38. <!-- 上传视频 -->
  39. <view style="margin-left: 56rpx" v-if="releaseTab == 1">
  40. <view class="sc_box">
  41. <text class="sc_tp">请上传视频</text>
  42. </view>
  43. <u-upload
  44. width="200rpx"
  45. height="200rpx"
  46. :fileList="fileList2"
  47. @afterRead="afterRead"
  48. @delete="deletePic"
  49. name="2"
  50. multiple
  51. :maxCount="10"
  52. accept="video"
  53. ></u-upload>
  54. </view>
  55. <view class="" style="background-color: #efefef; height: 20rpx; width: 100%"><!-- 分割背景 --></view>
  56. <view class="banxin" style="background-color: #ffffff; margin-top: 20rpx">
  57. <u--textarea v-model.trim="textVal" placeholder="请输入内容"></u--textarea>
  58. </view>
  59. <!-- 分区 -->
  60. <u-popup :show="showTanCeng" mode="bottom" @close="close" bgColor="#efefef">
  61. <view class="show_box">
  62. <view class="" style="display: flex; justify-content: space-between">
  63. <text @click="showTanCeng = false">取消</text>
  64. <text @click="showTanCeng = false" class="box_ok">确认</text>
  65. </view>
  66. <view class="box_fenqu" @click="show = true">
  67. <text>选择投稿类型</text>
  68. <view style="display: flex">
  69. <text style="color: #999999; font-size: 28rpx">{{ typeName }}</text>
  70. <uni-icons color="#999999" type="forward" size="20"></uni-icons>
  71. </view>
  72. </view>
  73. <!-- 添加标签 -->
  74. <view class="box_tj">
  75. <text style="color: #999999; font-size: 28rpx">选择内容类型</text>
  76. <view class="tag_box">
  77. <view class="" v-for="(item, index) in radios" :key="index">
  78. <u-tag size="mini" :text="item.name" :plain="!item.checked" shape="circle" type="warning" :name="index" @click="radioClick"></u-tag>
  79. </view>
  80. </view>
  81. </view>
  82. <u-picker
  83. title="选择投稿类型"
  84. :show="show"
  85. @close="show = false"
  86. ref="uPicker"
  87. @cancel="show = false"
  88. keyName="name"
  89. :closeOnClickOverlay="true"
  90. :columns="columns"
  91. @confirm="confirm"
  92. ></u-picker>
  93. </view>
  94. </u-popup>
  95. <view class="" style="background-color: #efefef; height: 20rpx; width: 100%"><!-- 分割背景 --></view>
  96. <view class="fq_box" @click="fenquBtn">
  97. <text>选择投稿类型</text>
  98. <view class="bq_box">
  99. <u-tag size="mini" shape="circle" text="文物" type="warning"></u-tag>
  100. <u-tag size="mini" shape="circle" text="非遗" type="success"></u-tag>
  101. <u-tag size="mini" shape="circle" text="民俗" type="error"></u-tag>
  102. <u-icon name="arrow-right" color="#666666" size="16"></u-icon>
  103. </view>
  104. </view>
  105. <!-- 评论 -->
  106. <view class="" style="background-color: #efefef; height: 20rpx; width: 100%"></view>
  107. <view class="queren" @click="isOk">确认发布</view>
  108. </view>
  109. </view>
  110. </template>
  111. <script>
  112. let that;
  113. export default {
  114. data() {
  115. return {
  116. releaseTab: 0,
  117. radios: [
  118. {
  119. name: '文章',
  120. id: 1,
  121. checked: true
  122. },
  123. {
  124. name: '视频',
  125. id: 2,
  126. checked: false
  127. },
  128. {
  129. name: '音频',
  130. id: 3,
  131. checked: false
  132. },
  133. {
  134. name: '相册',
  135. id: 4,
  136. checked: false
  137. }
  138. ],
  139. model_id: '' /* 投稿模型id */,
  140. typeId: 1 /* 投稿内容类型id */,
  141. main_body_column_id: '' /* 投稿栏目id */,
  142. typeName: '' /* 选中的类型 */,
  143. closeTag: true,
  144. showTanCeng: false,
  145. show: false,
  146. columns: [],
  147. titleVal: '',
  148. textVal: '',
  149. // switchval: '',
  150. // 上传的图片
  151. fileList1: [
  152. // {
  153. // url: 'https://huli-app.wenlvti.net/app_static/minnanhun/image/shouyeTJ.png'
  154. // },
  155. // {
  156. // url: 'https://huli-app.wenlvti.net/app_static/minnanhun/image/cs_shouye_tp.png'
  157. // }
  158. ],
  159. // 上传的视频
  160. fileList2: []
  161. };
  162. },
  163. onLoad() {
  164. that = this;
  165. this.main_body_id = this.$db.get('main_body_id');
  166. this.getColumnList();
  167. },
  168. computed: {
  169. uploadNumber() {
  170. return this.fileList1.length;
  171. }
  172. },
  173. methods: {
  174. getColumnList() {
  175. this.$api.getColumnList(
  176. {
  177. main_body_id: this.main_body_id,
  178. // 暂时传2
  179. model_id: '2'
  180. },
  181. function (res) {
  182. // console.log(res, 565656);
  183. let aa = [];
  184. aa.push(res.data);
  185. // console.log(aa, 13131313);
  186. that.columns = aa;
  187. }
  188. );
  189. },
  190. releaseBtn(i) {
  191. this.releaseTab = i;
  192. },
  193. fenquBtn() {
  194. // this.show = true;
  195. this.showTanCeng = true;
  196. },
  197. confirm(e) {
  198. console.log('confirm', e.value);
  199. this.model_id = e.value[0].model_id;
  200. this.main_body_column_id = e.value[0].id;
  201. this.typeName = e.value[0].name;
  202. this.show = false;
  203. },
  204. // 删除图片
  205. deletePic(event) {
  206. console.log(event, 'event');
  207. this[`fileList${event.name}`].splice(event.index, 1);
  208. },
  209. // 新增图片
  210. async afterRead(event) {
  211. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  212. let lists = [].concat(event.file);
  213. let fileListLen = this[`fileList${event.name}`].length;
  214. lists.map((item) => {
  215. this[`fileList${event.name}`].push({
  216. ...item,
  217. status: 'uploading',
  218. message: '上传中'
  219. });
  220. });
  221. for (let i = 0; i < lists.length; i++) {
  222. const result = await this.uploadFilePromise(lists[i].url);
  223. let item = this[`fileList${event.name}`][fileListLen];
  224. this[`fileList${event.name}`].splice(
  225. fileListLen,
  226. 1,
  227. Object.assign(item, {
  228. status: 'success',
  229. message: '',
  230. url: result
  231. })
  232. );
  233. fileListLen++;
  234. }
  235. },
  236. uploadFilePromise(url) {
  237. return new Promise((resolve, reject) => {
  238. let a = uni.uploadFile({
  239. url: 'https://mnhcdn.wenlvti.net/api/minnansoul/content/contribute', // 仅为示例,非真实的接口地址
  240. filePath: url,
  241. name: 'file',
  242. formData: {
  243. user: 'test'
  244. },
  245. success: (res) => {
  246. setTimeout(() => {
  247. resolve(res.data.data);
  248. }, 1000);
  249. }
  250. });
  251. });
  252. },
  253. radioClick(name) {
  254. this.radios.map((item, index) => {
  255. item.checked = index === name ? true : false;
  256. });
  257. this.typeId = this.radios[name].id;
  258. },
  259. // 投稿
  260. isOk() {
  261. let titleIsEmpty = this.titleVal === '';
  262. let textIsEmpty = this.textVal === '';
  263. // 先检查标题和内容是否为空
  264. if (titleIsEmpty) {
  265. that.$common.errorToShow('请填写投稿标题');
  266. return false; // 遇到错误时提前返回,避免后续条件的判断
  267. }
  268. if (textIsEmpty) {
  269. that.$common.errorToShow('请输入投稿内容');
  270. return false;
  271. }
  272. // 再检查模型ID、类型ID和栏目ID
  273. if (this.model_id === '' || this.main_body_column_id === '') {
  274. that.$common.errorToShow('请选择投稿类型');
  275. return false;
  276. }
  277. // 如果typeId是必须选择的,这里也要进行验证
  278. if (this.typeId === '') {
  279. that.$common.errorToShow('请选择内容类型');
  280. return false;
  281. } else {
  282. this.$api.contribute(
  283. {
  284. main_body_id: this.main_body_id,
  285. model_id: this.model_id,
  286. main_body_column_id: this.main_body_column_id,
  287. title: this.titleVal,
  288. type: this.typeId,
  289. content: this.titleVal
  290. },
  291. function (res) {
  292. if (res.code == 1) {
  293. that.$common.successToShow('投稿成功');
  294. } else {
  295. that.$common.errorToShow('投稿失败请稍后在试');
  296. console.log(that.fileList1, 6666);
  297. }
  298. }
  299. );
  300. }
  301. },
  302. close() {
  303. this.showTanCeng = false;
  304. // console.log('close');
  305. }
  306. }
  307. };
  308. </script>
  309. <style>
  310. .uptriangle {
  311. position: absolute;
  312. top: 120rpx;
  313. left: 170rpx;
  314. width: 0px;
  315. height: 0px;
  316. border: 30rpx solid transparent;
  317. border-top-color: #ca5642;
  318. }
  319. .uptriangle_active {
  320. position: absolute;
  321. top: 120rpx;
  322. left: 510rpx;
  323. width: 0px;
  324. height: 0px;
  325. border: 30rpx solid transparent;
  326. border-top-color: #ca5642;
  327. }
  328. .banxin {
  329. margin: 0 32rpx 0 32rpx;
  330. }
  331. .u-upload__button.data-v-69e2a36e {
  332. background-color: #efefef !important;
  333. }
  334. .u-upload__deletable.data-v-69e2a36e {
  335. width: 35rpx !important;
  336. height: 35rpx !important;
  337. }
  338. .u-transition {
  339. margin-right: 12rpx;
  340. }
  341. .tag_box {
  342. display: flex;
  343. margin-top: 20rpx;
  344. }
  345. .nav_fabu {
  346. position: relative;
  347. display: flex;
  348. justify-content: space-evenly;
  349. background-color: #ca5642;
  350. }
  351. .nav_left {
  352. display: flex;
  353. justify-content: start;
  354. align-items: center;
  355. width: 282rpx;
  356. height: 123rpx;
  357. font-size: 32rpx;
  358. background: #f4f4f9;
  359. border: 6px solid #ca5642;
  360. border-radius: 20rpx;
  361. }
  362. .left_icon {
  363. width: 50rpx;
  364. height: 50rpx;
  365. text-align: center;
  366. line-height: 50rpx;
  367. border-radius: 50%;
  368. margin-left: 50rpx;
  369. background-color: #ca5642;
  370. }
  371. .nav_right {
  372. display: flex;
  373. justify-content: start;
  374. align-items: center;
  375. width: 282rpx;
  376. height: 123rpx;
  377. font-size: 32rpx;
  378. background: #f4f4f9;
  379. border: 6px solid #ca5642;
  380. border-radius: 20rpx;
  381. }
  382. .right_icon {
  383. width: 50rpx;
  384. height: 50rpx;
  385. margin-left: 50rpx;
  386. border-radius: 50%;
  387. background-color: #4e7198;
  388. }
  389. .sc_box {
  390. display: flex;
  391. justify-content: space-between;
  392. margin: 0 55rpx 40rpx 10rpx;
  393. border-bottom: 1px #dedede solid;
  394. height: 60rpx;
  395. }
  396. .sc_tp {
  397. font-size: 30rpx;
  398. color: #000000;
  399. }
  400. .fq_box {
  401. display: flex;
  402. justify-content: space-between;
  403. margin: 0 32rpx 0 32rpx;
  404. height: 105rpx;
  405. align-items: center;
  406. }
  407. .box {
  408. background-color: #ffffff;
  409. padding-top: 20rpx;
  410. padding-bottom: 30rpx;
  411. }
  412. .bq_box {
  413. display: flex;
  414. align-items: center;
  415. }
  416. .pl_box {
  417. display: flex;
  418. justify-content: space-between;
  419. margin: 0 32rpx 0 32rpx;
  420. height: 105rpx;
  421. align-items: center;
  422. }
  423. .show_box {
  424. width: 100%;
  425. height: 500rpx;
  426. padding: 20rpx;
  427. }
  428. .queren {
  429. height: 70rpx;
  430. background-color: #ca5642;
  431. border-radius: 35rpx;
  432. font-size: 30rpx;
  433. color: #ffffff;
  434. text-align: center;
  435. line-height: 68rpx;
  436. margin: 0 32rpx 0 32rpx;
  437. }
  438. .box_ok {
  439. line-height: 50rpx;
  440. text-align: center;
  441. color: #ffffff;
  442. width: 93rpx;
  443. height: 52rpx;
  444. background: #ca5642;
  445. border-radius: 26rpx;
  446. }
  447. .box_fenqu {
  448. display: flex;
  449. justify-content: space-between;
  450. align-items: center;
  451. border-radius: 20rpx;
  452. margin-top: 20rpx;
  453. height: 105rpx;
  454. background-color: #ffffff;
  455. font-size: 30rpx;
  456. padding: 20rpx;
  457. }
  458. .box_tj {
  459. height: 300rpx;
  460. border-radius: 20rpx;
  461. background-color: #ffffff;
  462. margin-top: 20rpx;
  463. padding: 20rpx;
  464. }
  465. </style>