touGao.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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">
  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">
  10. <view class="left_icon"><uni-icons type="compose" size="20" color=" #ffffff"></uni-icons></view>
  11. <text>发照片</text>
  12. </view>
  13. </view>
  14. <!-- 上传发布组件 -->
  15. <view class="" style="margin-bottom: 20rpx">
  16. <u--input v-model="titleVal" customStyle="background-color: #ffffff;height: 105rpx;" placeholder="请填写标题" border="surround" clearable></u--input>
  17. </view>
  18. <view class="box">
  19. <view class="sc_box">
  20. <text class="sc_tp">请上传图片</text>
  21. <text class="sc_tp">{{ uploadNumber + '/' + 9 }}</text>
  22. </view>
  23. <view style="margin-left: 56rpx">
  24. <u-upload
  25. width="200rpx"
  26. height="200rpx"
  27. :maxCount="9"
  28. :deletable="true"
  29. :fileList="fileList1"
  30. @afterRead="afterRead"
  31. @delete="deletePic"
  32. name="1"
  33. multiple
  34. ></u-upload>
  35. </view>
  36. <view class="" style="background-color: #efefef; height: 20rpx; width: 100%"><!-- 分割背景 --></view>
  37. <view class="banxin" style="background-color: #ffffff; margin-top: 20rpx">
  38. <u--textarea v-model="textVal" placeholder="请输入内容"></u--textarea>
  39. </view>
  40. <!-- 分区 -->
  41. <u-popup :show="showTanCeng" mode="bottom" @close="close" bgColor="#efefef">
  42. <view class="show_box">
  43. <view class="" style="display: flex; justify-content: space-between">
  44. <text @click="showTanCeng = false">取消</text>
  45. <text class="box_ok">确认</text>
  46. </view>
  47. <view class="box_fenqu" @click="show = true">
  48. <text>分区</text>
  49. <view class="">
  50. <text style="color: #999999; font-size: 28rpx">生活 - 日常</text>
  51. <uni-icons color="#999999" type="forward" size="20"></uni-icons>
  52. </view>
  53. </view>
  54. <!-- 添加标签 -->
  55. <view class="box_tj">
  56. <!-- <text style="color: #999999; font-size: 28rpx">还可以添加 2 个标签</text> -->
  57. <view class="tag_box">
  58. <view class="" v-for="(item, index) in radios" :key="index">
  59. <u-tag size="mini" :text="`选项${index + 1}`" :plain="!item.checked" shape="circle" type="warning" :name="index" @click="radioClick"></u-tag>
  60. </view>
  61. </view>
  62. <!-- 推荐标签 -->
  63. <!-- <view class="" style="margin-top: 20rpx">
  64. <view style="color: #000000; font-size: 30rpx">推荐标签</view>
  65. <view class="" style="display: flex; margin-top: 20rpx">
  66. <u-tag size="mini" shape="circle" text="标签" type="warning"></u-tag>
  67. <u-tag size="mini" shape="circle" text="标签" type="success"></u-tag>
  68. </view>
  69. </view> -->
  70. </view>
  71. <u-picker
  72. title="选择分区"
  73. :show="show"
  74. @close="show = false"
  75. ref="uPicker"
  76. @cancel="show = false"
  77. keyName="label"
  78. :closeOnClickOverlay="true"
  79. :columns="columns"
  80. @confirm="confirm"
  81. @change="changeHandler"
  82. ></u-picker>
  83. </view>
  84. </u-popup>
  85. <view class="" style="background-color: #efefef; height: 20rpx; width: 100%"><!-- 分割背景 --></view>
  86. <view class="fq_box" @click="fenquBtn">
  87. <text>选择投稿类型</text>
  88. <view class="bq_box">
  89. <u-tag size="mini" shape="circle" text="文物" type="warning"></u-tag>
  90. <u-tag size="mini" shape="circle" text="非遗" type="success"></u-tag>
  91. <u-tag size="mini" shape="circle" text="民俗" type="error"></u-tag>
  92. <u-icon name="arrow-right" color="#666666" size="16"></u-icon>
  93. </view>
  94. </view>
  95. <!-- 评论 -->
  96. <view class="" style="background-color: #efefef; height: 20rpx; width: 100%"></view>
  97. <!-- <view class="pl_box">
  98. <text>开启评论</text>
  99. <u-switch activeColor="#5ac725" v-model="switchval" @change="change"></u-switch>
  100. </view> -->
  101. <view class="queren" @click="isOk">确认发布</view>
  102. </view>
  103. </view>
  104. </template>
  105. <script>
  106. let that;
  107. export default {
  108. data() {
  109. return {
  110. radios: [
  111. {
  112. checked: true
  113. },
  114. {
  115. checked: false
  116. },
  117. {
  118. checked: false
  119. }
  120. ],
  121. closeTag: true,
  122. tags: [
  123. { label: '标签1', type: 'primary', closable: true },
  124. { label: '标签2', type: 'warning ', closable: true },
  125. { label: '标签3', type: 'success', closable: true }
  126. ],
  127. showTanCeng: false,
  128. show: false,
  129. columns: [
  130. [
  131. { label: '中国', id: 1 },
  132. { label: '美国', id: 2 }
  133. ],
  134. ['深圳', '厦门', '上海', '拉萨']
  135. ],
  136. columnData: [
  137. ['深圳', '厦门', '上海', '拉萨'],
  138. ['得州', '华盛顿', '纽约', '阿拉斯加']
  139. ],
  140. titleVal: '',
  141. textVal: '',
  142. // switchval: '',
  143. fileList1: [
  144. {
  145. url: 'https://huli-app.wenlvti.net/app_static/minnanhun/image/shouyeTJ.png'
  146. },
  147. {
  148. url: 'https://huli-app.wenlvti.net/app_static/minnanhun/image/cs_shouye_tp.png'
  149. }
  150. ]
  151. };
  152. },
  153. onLoad() {
  154. that = this;
  155. this.main_body_id = this.$db.get('main_body_id');
  156. },
  157. computed: {
  158. uploadNumber() {
  159. return this.fileList1.length;
  160. }
  161. },
  162. methods: {
  163. fenquBtn() {
  164. // this.show = true;
  165. this.showTanCeng = true;
  166. },
  167. // 关闭标签
  168. closeBtn(item) {
  169. console.log(item);
  170. this.tags.splice(this.tags.indexOf(item), 1);
  171. },
  172. // 分区组件方法
  173. changeHandler(e) {
  174. const {
  175. columnIndex,
  176. value,
  177. values, // values为当前变化列的数组内容
  178. index,
  179. // 微信小程序无法将picker实例传出来,只能通过ref操作
  180. picker = this.$refs.uPicker
  181. } = e;
  182. // 当第一列值发生变化时,变化第二列(后一列)对应的选项
  183. if (columnIndex === 0) {
  184. // picker为选择器this实例,变化第二列对应的选项
  185. picker.setColumnValues(1, this.columnData[index]);
  186. }
  187. },
  188. //// 分区组件方法 回调参数为包含columnIndex、value、values
  189. confirm(e) {
  190. console.log('confirm', e.value[0]);
  191. this.show = false;
  192. },
  193. // change(e) {
  194. // console.log('change', e);
  195. // },
  196. // 删除图片
  197. deletePic(event) {
  198. console.log(event, 'event');
  199. this[`fileList${event.name}`].splice(event.index, 1);
  200. },
  201. // 新增图片
  202. async afterRead(event) {
  203. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  204. let lists = [].concat(event.file);
  205. let fileListLen = this[`fileList${event.name}`].length;
  206. lists.map((item) => {
  207. this[`fileList${event.name}`].push({
  208. ...item,
  209. status: 'uploading',
  210. message: '上传中'
  211. });
  212. });
  213. for (let i = 0; i < lists.length; i++) {
  214. const result = await this.uploadFilePromise(lists[i].url);
  215. let item = this[`fileList${event.name}`][fileListLen];
  216. this[`fileList${event.name}`].splice(
  217. fileListLen,
  218. 1,
  219. Object.assign(item, {
  220. status: 'success',
  221. message: '',
  222. url: result
  223. })
  224. );
  225. fileListLen++;
  226. }
  227. },
  228. uploadFilePromise(url) {
  229. return new Promise((resolve, reject) => {
  230. let a = uni.uploadFile({
  231. url: 'http://192.168.2.21:7001/upload', // 仅为示例,非真实的接口地址
  232. filePath: url,
  233. name: 'file',
  234. formData: {
  235. user: 'test'
  236. },
  237. success: (res) => {
  238. setTimeout(() => {
  239. resolve(res.data.data);
  240. }, 1000);
  241. }
  242. });
  243. });
  244. },
  245. radioClick(name) {
  246. this.radios.map((item, index) => {
  247. item.checked = index === name ? true : false;
  248. });
  249. },
  250. isOk() {
  251. if (this.titleVal == '' || this.titleVal == undefined) {
  252. that.$common.errorToShow('请填写标题');
  253. }
  254. if (this.textVal == '' || this.textVal == undefined) {
  255. that.$common.errorToShow('请输入内容');
  256. } else {
  257. // this.$api.contribute({}, function (res) {
  258. // console.log(res, 6666);
  259. // });
  260. }
  261. },
  262. close() {
  263. this.showTanCeng = false;
  264. // console.log('close');
  265. }
  266. }
  267. };
  268. </script>
  269. <style>
  270. .banxin {
  271. margin: 0 32rpx 0 32rpx;
  272. }
  273. .u-upload__button.data-v-69e2a36e {
  274. background-color: #efefef !important;
  275. }
  276. .u-upload__deletable.data-v-69e2a36e {
  277. width: 35rpx !important;
  278. height: 35rpx !important;
  279. }
  280. .u-transition {
  281. margin-right: 12rpx;
  282. }
  283. .tag_box {
  284. display: flex;
  285. }
  286. /* .u-icon__icon.data-v-2ee87dc9 {
  287. font-size: 25rpx !important;
  288. line-height: 26rpx !important;
  289. } */
  290. .nav_fabu {
  291. display: flex;
  292. justify-content: space-evenly;
  293. background-color: #ca5642;
  294. }
  295. .nav_left {
  296. display: flex;
  297. justify-content: start;
  298. align-items: center;
  299. width: 282rpx;
  300. height: 123rpx;
  301. font-size: 32rpx;
  302. background: #f4f4f9;
  303. border: 6px solid #ca5642;
  304. border-radius: 20rpx;
  305. }
  306. .left_icon {
  307. width: 50rpx;
  308. height: 50rpx;
  309. text-align: center;
  310. line-height: 50rpx;
  311. border-radius: 50%;
  312. margin-left: 50rpx;
  313. background-color: #ca5642;
  314. }
  315. .nav_right {
  316. display: flex;
  317. justify-content: start;
  318. align-items: center;
  319. width: 282rpx;
  320. height: 123rpx;
  321. font-size: 32rpx;
  322. background: #f4f4f9;
  323. border: 6px solid #ca5642;
  324. border-radius: 20rpx;
  325. }
  326. .right_icon {
  327. width: 50rpx;
  328. height: 50rpx;
  329. margin-left: 50rpx;
  330. border-radius: 50%;
  331. background-color: #4e7198;
  332. }
  333. .sc_box {
  334. display: flex;
  335. justify-content: space-between;
  336. margin: 0 55rpx 40rpx 55rpx;
  337. border-bottom: 1px #dedede solid;
  338. height: 60rpx;
  339. }
  340. .sc_tp {
  341. font-size: 30rpx;
  342. color: #000000;
  343. }
  344. .fq_box {
  345. display: flex;
  346. justify-content: space-between;
  347. margin: 0 32rpx 0 32rpx;
  348. height: 105rpx;
  349. align-items: center;
  350. }
  351. .box {
  352. background-color: #ffffff;
  353. padding-top: 20rpx;
  354. padding-bottom: 30rpx;
  355. }
  356. .bq_box {
  357. display: flex;
  358. align-items: center;
  359. }
  360. .pl_box {
  361. display: flex;
  362. justify-content: space-between;
  363. margin: 0 32rpx 0 32rpx;
  364. height: 105rpx;
  365. align-items: center;
  366. }
  367. .show_box {
  368. width: 100%;
  369. height: 500rpx;
  370. padding: 20rpx;
  371. }
  372. .queren {
  373. height: 70rpx;
  374. background-color: #ca5642;
  375. border-radius: 35rpx;
  376. font-size: 30rpx;
  377. color: #ffffff;
  378. text-align: center;
  379. line-height: 68rpx;
  380. margin: 0 32rpx 0 32rpx;
  381. }
  382. .box_ok {
  383. line-height: 50rpx;
  384. text-align: center;
  385. color: #ffffff;
  386. width: 93rpx;
  387. height: 52rpx;
  388. background: #ca5642;
  389. border-radius: 26rpx;
  390. }
  391. .box_fenqu {
  392. display: flex;
  393. justify-content: space-between;
  394. align-items: center;
  395. border-radius: 20rpx;
  396. margin-top: 20rpx;
  397. height: 105rpx;
  398. background-color: #ffffff;
  399. font-size: 30rpx;
  400. padding: 20rpx;
  401. }
  402. .box_tj {
  403. height: 300rpx;
  404. border-radius: 20rpx;
  405. background-color: #ffffff;
  406. margin-top: 20rpx;
  407. padding: 20rpx;
  408. }
  409. </style>