publish.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <template>
  2. <view class="publish">
  3. <u-navbar leftIconColor="#000" :fixed="false" leftIconSize="48" :autoBack="true">
  4. <view class="" slot="left" style="color: #DC3C23;">
  5. <!-- Cancel -->
  6. {{ $t('news.lab9') }}
  7. </view>
  8. <view class="" slot="center" style="">
  9. <!-- Publish -->
  10. {{ $t('news.lab10') }}
  11. </view>
  12. <view class="flex-end" slot="right" @click="submit()">
  13. <text class="Confirm">
  14. <!-- Confirm -->
  15. {{ $t('news.confirm') }}
  16. </text>
  17. </view>
  18. </u-navbar>
  19. <!-- <view class="select" @click="showType = true">
  20. 获取分类:{{select.name || '点击获取'}}
  21. </view> -->
  22. <view class="" style="overflow: hidden;">
  23. <u--textarea @focus="focus" @blur="blur" class="input" maxlength="-1" height="308" v-model="value2" confirmType="done"
  24. border="none" placeholder="Please enter your content" ></u--textarea>
  25. </view>
  26. <view class="" style="padding: 24rpx;">
  27. <u-upload :fileList="fileList1" @afterRead="afterRead" uploadText="loading" @delete="deletePic" imageMode="scaleToFill" name="1" width="200" height="200" multiple :maxCount="10" v-if="type == 1">
  28. <image src="/static/image/videos/Upload@2x.png"
  29. mode="aspectFill" style="width: 200rpx;height: 200rpx;"></image>
  30. </u-upload>
  31. <u-upload :fileList="fileList1" @afterRead="afterRead" uploadText="loading" @delete="deletePic" accept="video" name="1" width="200" height="200" multiple :maxCount="1" v-if="type == 2">
  32. <image src="/static/image/videos/Uploadthevideo@2x.png"
  33. mode="aspectFill" style="width: 200rpx;height: 200rpx;"></image>
  34. </u-upload>
  35. </view>
  36. <view class="operation flex-start" v-if="show">
  37. <image src="/static/image/news/pulist-1.png" mode="" @click="type = 1"></image>
  38. <image src="/static/image/news/pulist-2.png" mode="" @click="type = 2"></image>
  39. <view class="font24" @click="showType = true">
  40. {{select.name || $t('news.select')}}
  41. </view>
  42. </view>
  43. <u-picker keyName="name" :cancelText="$t('news.cancel')" :confirmText="$t('news.confirm')" @close="close" :closeOnClickOverlay="true" :show="showType" :columns="columns" @confirm="confirm" @cancel="showType = false"></u-picker>
  44. </view>
  45. </template>
  46. <script>
  47. export default {
  48. data() {
  49. return {
  50. type:0,
  51. value2: '',
  52. showType:false,
  53. show: false,
  54. columns:[],
  55. select:{
  56. name:''
  57. },
  58. status:'ok',
  59. CovrUrl:'',
  60. fileList1: [],
  61. }
  62. },
  63. computed:{
  64. qiuNiu() {
  65. return this.$store.state.qiuNiu
  66. }
  67. },
  68. watch:{
  69. type(e) {
  70. this.$forceUpdate();
  71. console.log(e);
  72. this.fileList1 = []
  73. }
  74. },
  75. onLoad() {
  76. this.getType()
  77. },
  78. methods: {
  79. /* 提交数据 */
  80. submit() {
  81. if (this.$store.state.isLogin != 1) {
  82. this.$toUrl('/pages/login/login')
  83. return
  84. }
  85. let data = {
  86. flie:[],
  87. classification_id:this.select.id,
  88. title:this.value2,
  89. }
  90. if(this.type == 1) {
  91. data.flie = this.fileList1.map(item=>item.url)
  92. }else if(this.type == 2) {
  93. let video = this.fileList1.map(item=>item.url)
  94. data.flie = [{img:this.CovrUrl,video:video[0]}]
  95. }
  96. if(this.status != 'ok') {
  97. return this.$toast(this.$t('news.lab11'))
  98. }
  99. uni.$u.http.post('/api/Circleuser/insert',data).then(res=>{
  100. this.$back()
  101. let pages = getCurrentPages();
  102. let prevPage = pages[pages.length - 2]; //上一页页面实例
  103. prevPage.$vm.luntanPage = 1;
  104. prevPage.$vm.getLuntan()
  105. }).catch(res=>{})
  106. },
  107. // 获取类型
  108. getType() {
  109. uni.$u.http.get('/api/circle/classification',{}).then(res=>{
  110. let list = res || []
  111. this.columns.push(list)
  112. if (list[0]) {
  113. this.select = list[0]
  114. }
  115. }).catch(res=>{})
  116. },
  117. close() {
  118. this.showType = false
  119. },
  120. /* 选中的分类 */
  121. confirm(e) {
  122. console.log(e);
  123. this.select= e.value[0]
  124. this.showType =false
  125. },
  126. // 获取焦点
  127. focus(e) {
  128. this.show = true
  129. },
  130. // 失去焦点
  131. blur(e) {
  132. // this.show = false
  133. },
  134. // 删除图片
  135. deletePic(event) {
  136. this[`fileList${event.name}`].splice(event.index, 1)
  137. },
  138. // 新增图片
  139. async afterRead(event) {
  140. this.status = 'loading'
  141. // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
  142. let lists = [].concat(event.file)
  143. let fileListLen = this[`fileList${event.name}`].length
  144. lists.map((item) => {
  145. this[`fileList${event.name}`].push({
  146. ...item,
  147. status: 'uploading',
  148. message: 'loading'
  149. })
  150. })
  151. for (let i = 0; i < lists.length; i++) {
  152. const result = await this.uploadFilePromise(lists[i])
  153. if(this.type == 2) {
  154. this.parseBlob(result)
  155. }
  156. let item = this[`fileList${event.name}`][fileListLen]
  157. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  158. status: 'success',
  159. message: '',
  160. url: result
  161. }))
  162. fileListLen++
  163. }
  164. this.status = 'ok'
  165. },
  166. uploadFilePromise(item) {
  167. let { token,domain,uploadHost,httpsdomain } = this.qiuNiu;
  168. let type = item.name.slice(-7);
  169. let key = new Date().getTime() + type;
  170. return new Promise((resolve, reject) => {
  171. let a = uni.uploadFile({
  172. url: 'https://' + uploadHost, // 仅为示例,非真实的接口地址
  173. filePath: item.url,
  174. name: 'file',
  175. formData: {
  176. key:key,
  177. token: token
  178. },
  179. success: (res) => {
  180. let data = JSON.parse(res.data)
  181. console.log(data);
  182. console.log(httpsdomain + '/' + data.key);
  183. setTimeout(() => {
  184. resolve(httpsdomain + '/' + data.key)
  185. }, 1000)
  186. }
  187. });
  188. })
  189. },
  190. parseBlob(base64) {
  191. let key = new Date().getTime() + '.png';
  192. var blob = `${base64}?vframe/jpg/offset/0`
  193. let {
  194. token,
  195. domain,
  196. uploadHost,
  197. httpsdomain
  198. } = this.qiuNiu;
  199. uni.uploadFile({
  200. url: 'https://' + uploadHost, // 仅为示例,非真实的接口地址
  201. filePath: blob,
  202. name: 'file',
  203. formData: {
  204. key: key,
  205. token: token
  206. },
  207. success: (res) => {
  208. let data = JSON.parse(res.data)
  209. this.CovrUrl = httpsdomain + '/' + data.key
  210. },
  211. })
  212. },
  213. }
  214. }
  215. </script>
  216. <style lang="scss">
  217. /deep/.u-upload__wrap__preview__other__text {
  218. display: none;
  219. }
  220. page {
  221. background: #F3F3F7;
  222. }
  223. .select {
  224. color: #333;
  225. padding: 24rpx;
  226. }
  227. .input {
  228. margin: 20rpx 24rpx;
  229. }
  230. .Confirm {
  231. color: #fff;
  232. border-radius: 40rpx;
  233. padding: 6rpx 24rpx;
  234. background-color: $color2;
  235. }
  236. .operation {
  237. position: fixed;
  238. bottom: 0;
  239. left: 0;
  240. right: 0;
  241. padding: 32rpx;
  242. background-color: white;
  243. image {
  244. width: 48rpx;
  245. height: 48rpx;
  246. margin-right: 64rpx;
  247. }
  248. view {
  249. color: #fff;
  250. padding: 8rpx 30rpx;
  251. border-radius: 40px;
  252. background-color: $color2;
  253. }
  254. }
  255. </style>