TouGao.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <template>
  2. <view class="box">
  3. <view class="ban_box">
  4. <view class="tit_box">
  5. <view class="title">{{ titList.title }}:</view>
  6. <u--input customStyle="background-color:#ffffff" placeholder="请输入标题" border="surround" v-model.trim="titVal"></u--input>
  7. </view>
  8. <view v-if="titList.typeVal" class="tit_box" @click="show = true">
  9. <view class="title">文章类型:</view>
  10. <view class="lx">
  11. <view :style="{ color: typesofs ? '#000' : '#c0c4cc' }">{{ typesofs ? typesofs : '请选择类型' }}</view>
  12. <u-icon name="arrow-down" color="#c0c4cc" size="20"></u-icon>
  13. </view>
  14. </view>
  15. <view class="tit_box" v-if="titList">
  16. <view class="title" style="margin-top: -120rpx">{{ titList.content }}:</view>
  17. <u--textarea v-model.trim="textVal" placeholder="请输入内容"></u--textarea>
  18. </view>
  19. <!-- 内容 -->
  20. <view v-if="titList.typeVal" class="tit_box">
  21. <view class="title" style="margin-top: -120rpx">文物价值:</view>
  22. <u--textarea v-model.trim="textVal2" placeholder="请输入内容"></u--textarea>
  23. </view>
  24. </view>
  25. <!-- 图片 -->
  26. <view class="" style="margin-top: 40rpx">
  27. <view class="" style="margin-left: 32rpx; margin-bottom: 20rpx">上传图片:{{ uploadNumber + '/' + 9 }}</view>
  28. <view class="">
  29. <!-- 上传照片 -->
  30. <view style="margin-left: 56rpx">
  31. <u-upload
  32. width="200rpx"
  33. height="200rpx"
  34. :maxCount="9"
  35. :deletable="true"
  36. :fileList="fileList1"
  37. @afterRead="afterRead"
  38. @delete="deletePic"
  39. name="1"
  40. multiple
  41. ></u-upload>
  42. </view>
  43. </view>
  44. </view>
  45. <!-- 视频 -->
  46. <view class="" style="margin-left: 50rpx">
  47. <view style="margin: 20rpx 0 20rpx -15rpx">请上传视频:</view>
  48. <u-upload width="200rpx" height="200rpx" :fileList="fileList2" @afterRead="afterRead" @delete="deletePic" name="2" multiple :maxCount="10" accept="video"></u-upload>
  49. </view>
  50. <u-picker :show="show" @cancel="show = false" :columns="columns" @close="close" :closeOnClickOverlay="true" @confirm="confirm"></u-picker>
  51. <view @click="isOk" class="tg_box">{{ titList.okTit }}</view>
  52. </view>
  53. </template>
  54. <script>
  55. export default {
  56. name: 'TouGao',
  57. props: {
  58. titList: {
  59. type: Object,
  60. default: () => {
  61. return {
  62. okTit: '投稿',
  63. title: '文章标题',
  64. content: '文章内容',
  65. typeVal: true
  66. };
  67. }
  68. }
  69. },
  70. data() {
  71. return {
  72. typesofs: '',
  73. titVal: '',
  74. textVal: '',
  75. textVal2: '',
  76. show: false,
  77. columns: [['古建筑', '近现代史迹', '古遗址']],
  78. // 上传的图片
  79. fileList1: [
  80. {
  81. url: 'https://huli-app.wenlvti.net/app_static/minnanhun/image/shouyeTJ.png'
  82. }
  83. ]
  84. };
  85. },
  86. computed: {
  87. uploadNumber() {
  88. return this.fileList1.length;
  89. }
  90. },
  91. methods: {
  92. confirm(e) {
  93. console.log('confirm', e);
  94. this.typesofs = e.value[0];
  95. this.show = false;
  96. },
  97. async afterRead(event) {
  98. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  99. let lists = [].concat(event.file);
  100. let fileListLen = this[`fileList${event.name}`].length;
  101. lists.map((item) => {
  102. this[`fileList${event.name}`].push({
  103. ...item,
  104. status: 'uploading',
  105. message: '上传中'
  106. });
  107. });
  108. for (let i = 0; i < lists.length; i++) {
  109. const result = await this.uploadFilePromise(lists[i].url);
  110. let item = this[`fileList${event.name}`][fileListLen];
  111. this[`fileList${event.name}`].splice(
  112. fileListLen,
  113. 1,
  114. Object.assign(item, {
  115. status: 'success',
  116. message: '',
  117. url: result
  118. })
  119. );
  120. fileListLen++;
  121. }
  122. },
  123. // 删除图片
  124. deletePic(event) {
  125. console.log(event, 'event');
  126. this[`fileList${event.name}`].splice(event.index, 1);
  127. },
  128. uploadFilePromise(url) {
  129. return new Promise((resolve, reject) => {
  130. let a = uni.uploadFile({
  131. url: 'https://mnhcdn.wenlvti.net/api/minnansoul/content/contribute', // 仅为示例,非真实的接口地址
  132. filePath: url,
  133. name: 'file',
  134. formData: {
  135. user: 'test'
  136. },
  137. success: (res) => {
  138. setTimeout(() => {
  139. resolve(res.data.data);
  140. }, 1000);
  141. }
  142. });
  143. });
  144. },
  145. // 投稿
  146. // isOk() {
  147. // let titleIsEmpty = this.titleVal === '';
  148. // let textIsEmpty = this.textVal === '';
  149. // // 先检查标题和内容是否为空
  150. // if (titleIsEmpty) {
  151. // that.$common.errorToShow('请填写投稿标题');
  152. // return false; // 遇到错误时提前返回,避免后续条件的判断
  153. // }
  154. // if (textIsEmpty) {
  155. // that.$common.errorToShow('请输入投稿内容');
  156. // return false;
  157. // }
  158. // // 再检查模型ID、类型ID和栏目ID
  159. // if (this.model_id === '' || this.main_body_column_id === '') {
  160. // that.$common.errorToShow('请选择投稿类型');
  161. // return false;
  162. // }
  163. // // 如果typeId是必须选择的,这里也要进行验证
  164. // if (this.typeId === '') {
  165. // that.$common.errorToShow('请选择内容类型');
  166. // return false;
  167. // } else {
  168. // this.$api.contribute(
  169. // {
  170. // main_body_id: this.main_body_id,
  171. // model_id: this.model_id,
  172. // main_body_column_id: this.main_body_column_id,
  173. // title: this.titleVal,
  174. // type: this.typeId,
  175. // content: this.titleVal
  176. // },
  177. // function (res) {
  178. // if (res.code == 1) {
  179. // that.$common.successToShow('投稿成功');
  180. // // console.log(res, 6666);
  181. // } else {
  182. // that.$common.errorToShow('投稿失败请稍后再试');
  183. // }
  184. // }
  185. // );
  186. // }
  187. // },
  188. close() {
  189. this.show = false;
  190. }
  191. }
  192. };
  193. </script>
  194. <style>
  195. .img {
  196. width: 100%;
  197. height: 100%;
  198. border-radius: 50%;
  199. }
  200. .fk_box {
  201. width: 90%;
  202. display: flex;
  203. justify-content: space-between;
  204. margin: auto;
  205. margin-top: 20rpx;
  206. font-size: 30rpx;
  207. color: #313131;
  208. text-align: center;
  209. }
  210. .jianyi {
  211. width: 170rpx;
  212. height: 60rpx;
  213. line-height: 58rpx;
  214. border: 2rpx solid #fadcb3;
  215. background-color: #fdf7ee;
  216. border-radius: 10rpx;
  217. }
  218. /deep/.u-input--radius.data-v-113bc24f,
  219. .u-input--square.data-v-113bc24f {
  220. background-color: #ffffff !important;
  221. }
  222. /deep/.u-input.data-v-113bc24f {
  223. background-color: #ffffff !important;
  224. }
  225. .ban_box {
  226. width: 90%;
  227. margin: auto;
  228. margin-top: 40rpx;
  229. }
  230. .tit_box {
  231. width: 680rpx;
  232. display: flex;
  233. justify-content: space-between;
  234. align-items: center;
  235. margin-top: 40rpx;
  236. }
  237. .title {
  238. margin-right: 10rpx;
  239. font-size: 30rpx;
  240. color: #313131;
  241. }
  242. .lx {
  243. display: flex;
  244. justify-content: space-between;
  245. width: 540rpx;
  246. height: 70rpx;
  247. background-color: #ffffff;
  248. border-radius: 10rpx;
  249. line-height: 70rpx;
  250. color: #c0c4cc;
  251. padding-left: 20rpx;
  252. padding-right: 20rpx;
  253. }
  254. .tg_box {
  255. width: 390rpx;
  256. height: 74rpx;
  257. margin: auto;
  258. margin-top: 40rpx;
  259. font-size: 34rpx;
  260. background-color: #f5c382;
  261. text-align: center;
  262. font-weight: bold;
  263. color: #313131;
  264. border-radius: 10rpx;
  265. line-height: 74rpx;
  266. }
  267. </style>