send.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. <template>
  2. <view class="page"
  3. @touchstart="touchStart"
  4. @touchend="touchEnd">
  5. <form>
  6. <view class="uni-textarea">
  7. <textarea placeholder="这一刻的想法..."
  8. v-model="input_content" />
  9. </view>
  10. <view class="uni-list list-pd" v-if="type === 'image'">
  11. <view class=" cell-pd">
  12. <view class="uni-uploader">
  13. <view class="uni-uploader-head">
  14. <view class="uni-uploader-title"></view>
  15. <view class="uni-uploader-info">{{imageList.length}}/9</view>
  16. </view>
  17. <view class="uni-uploader-body">
  18. <view class="uni-uploader__files">
  19. <block v-for="(image,index) in imageList" :key="index">
  20. <view class="uni-uploader__file" style="position: relative;">
  21. <image class="uni-uploader__img" mode="aspectFill" :src="image" :data-src="image" @tap="previewImage"></image>
  22. <view class="close-view" @click="close(index)">x</view>
  23. </view>
  24. </block>
  25. <view class="uni-uploader__input-box" v-show="imageList.length < 9">
  26. <view class="uni-uploader__input" @tap="chooseImage"></view>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. </view>
  33. <view v-if="type === 'video'" class="uni-list list-pd">
  34. <view class=" cell-pd">
  35. <view class="uni-uploader">
  36. <view class="uni-uploader-head">
  37. <view class="uni-uploader-title"></view>
  38. <view class="uni-uploader-info">请选择上传视频</view>
  39. </view>
  40. <view class="uni-uploader-body">
  41. <view class="uni-uploader__files">
  42. <block v-for="(image,index) in videoList" :key="index">
  43. <view class="uni-uploader__file" style="position: relative;">
  44. <video class="uni-uploader__img" mode="aspectFill" :src="image" :data-src="image" @tap="previewImage"></video>
  45. <view class="close-view" @click="closeVideo()">x</view>
  46. </view>
  47. </block>
  48. <view class="uni-uploader__input-box" v-show="videoList.length === 0">
  49. <view class="uni-uploader__input" @tap="chooseVideo"></view>
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. <view class="list_view">
  57. <!-- <view class="item_view">
  58. <view>卖货</view>
  59. <switch @change="canPay" />
  60. </view>
  61. <view class="item_view">
  62. <view>价格</view>
  63. <input class="uni-input" type="number" placeholder="请输入收费金额" v-model="pay_amount"/>
  64. </view> -->
  65. </view>
  66. </form>
  67. <!-- <view v-show="showVedio"
  68. class="showVedio">
  69. <video autoplay="true"
  70. object-fit="fill"
  71. page-gesture="true"
  72. controls="false"
  73. style="height: 100%;width: 100%"
  74. id="myVideo"
  75. :src="videoPath"
  76. @error="videoErrorCallback">
  77. <cover-image @tap="showVedio = false"
  78. src="/static/theme/default/my/close.png"
  79. class="cloneBut"></cover-image>
  80. </video>
  81. </view> -->
  82. </view>
  83. </template>
  84. <script>
  85. import _get from '../../../common/_get';
  86. import _hook from '../../../common/_hook';
  87. import _data from '../../../common/_data';
  88. var sourceType = [
  89. ['camera'],
  90. ['album'],
  91. ['camera', 'album']
  92. ]
  93. var sizeType = [
  94. ['compressed'],
  95. ['original'],
  96. ['compressed', 'original']
  97. ]
  98. export default {
  99. data () {
  100. return {
  101. // title: 'choose/previewImage',
  102. pay_amount:'',
  103. input_content: '',
  104. imageList: [],
  105. videoList: [],
  106. sourceTypeIndex: 2,
  107. sizeTypeIndex: 2,
  108. sizeType: ['压缩', '原图', '压缩或原图'],
  109. countIndex: 8,
  110. count: [1, 2, 3, 4, 5, 6, 7, 8, 9],
  111. sourceType: ['拍摄', '相册', '拍摄或相册'],
  112. VideoOfImagesShow: true,
  113. cameraList: [{
  114. value: 'back',
  115. name: '后置摄像头',
  116. checked: 'true'
  117. },
  118. {
  119. value: 'front',
  120. name: '前置摄像头'
  121. }],
  122. cameraIndex: 0,
  123. //侧滑返回start
  124. startX: 0, //点击屏幕起始位置
  125. movedX: 0, //横向移动的距离
  126. endX: 0, //接触屏幕后移开时的位置
  127. //end
  128. send_status: false,
  129. can_pay:0,
  130. }
  131. },
  132. onLoad (option) {
  133. this.type = option.type;
  134. this.user_id = option.user_id;
  135. console.log(this.type)
  136. },
  137. onShow () {
  138. _hook.routeSonHook();
  139. },
  140. onUnload () {
  141. this.imageList = [],
  142. this.sourceTypeIndex = 2,
  143. this.sourceType = ['拍照', '相册', '拍照或相册'],
  144. this.sizeTypeIndex = 2,
  145. this.sizeType = ['压缩', '原图', '压缩或原图'],
  146. this.countIndex = 8;
  147. },
  148. methods: {
  149. canPay(e){
  150. if(e.target.value){
  151. this.can_pay = 1;
  152. }else {
  153. this.can_pay = 0;
  154. }
  155. },
  156. publish () {
  157. if (!this.input_content) {
  158. uni.showModal({ content: '内容不能为空', showCancel: false, });
  159. return;
  160. }
  161. if (this.send_status) {
  162. return;
  163. }
  164. this.send_status = true;
  165. let _this = this;
  166. uni.showLoading({ title: '发布中' });
  167. // #ifndef H5
  168. //var location = await this.getLocation(); //位置信息,可删除
  169. // #endif
  170. ((callback) => {
  171. let content = {
  172. text: this.input_content,
  173. value: [],
  174. };
  175. let dataList = []
  176. if (this.type === 'image') {
  177. dataList = this.imageList
  178. } else {
  179. dataList = this.videoList
  180. }
  181. if (dataList.length) {
  182. for (var i = 0, len = dataList.length; i < len; i++) {
  183. _this.$httpSendFile({
  184. type: 2,
  185. local_url: dataList[i],
  186. data: { len: len },
  187. success (data) {
  188. content.value.push(data.save_name);
  189. if (content.value.length >= len) {
  190. content.pay_amount = _this.pay_amount;
  191. content.can_pay = _this.can_pay;
  192. content.video_path = data.video_path
  193. callback(content);
  194. }
  195. },
  196. fail () {
  197. _this.$httpSend({ path: '/im/upload/deleteCircleFile' });
  198. },
  199. });
  200. }
  201. return;
  202. }
  203. callback(content);
  204. })((content) => {
  205. /** 这里发送消息至朋友圈 */
  206. _this.$httpSend({
  207. path: '/im/circle/sendMsg',
  208. data: {
  209. content: JSON.stringify(content),
  210. },
  211. success_action: true,
  212. success (res) {
  213. uni.hideLoading();
  214. _this.send_status = false;
  215. if (res.err) {
  216. uni.showModal({
  217. content: '发布失败',
  218. });
  219. _this.$httpSend({ path: '/im/upload/deleteCircleFile' });
  220. return;
  221. }
  222. if (_this.imageList.length ||_this.videoList.length) {
  223. _this.$httpSend({ path: '/im/upload/circleFileAction', data: { circle_id: res.data.circle_id, } });
  224. }
  225. uni.showToast({
  226. icon: 'success',
  227. title: '发布成功',
  228. success () {
  229. let prefix = '';
  230. console.log("data.user_id",_this.user_id)
  231. if(_this.user_id > 0){
  232. prefix = '_user';
  233. }
  234. let circle_data = _data.localData('circle_data'+prefix);
  235. _get.getCircleList({
  236. time: (circle_data.length ? circle_data[0].time : 0),
  237. type: 0,
  238. user_id: _this.user_id,
  239. update:1
  240. });
  241. uni.navigateBack();
  242. }
  243. });
  244. },
  245. fail (err) {
  246. uni.hideLoading();
  247. uni.showModal({
  248. content: '发布失败',
  249. });
  250. _this.$httpSend({ path: '/im/upload/deleteCircleFile' });
  251. }
  252. });
  253. });
  254. },
  255. // #ifndef H5
  256. getLocation () {
  257. // h5中可能不支持,自己选择
  258. return new Promise((resolve, reject) => {
  259. uni.getLocation({
  260. type: 'wgs84',
  261. success: function (res) {
  262. resolve(res);
  263. },
  264. fail: (e) => {
  265. reject(e);
  266. }
  267. });
  268. });
  269. },
  270. // #endif
  271. close (e) {
  272. this.imageList.splice(e, 1);
  273. },
  274. closeVideo () {
  275. this.videoList = []
  276. },
  277. chooseVideo: async function () {
  278. let _this = this
  279. uni.chooseVideo({
  280. maxDuration: 60,
  281. count: 1,
  282. camera: this.cameraList[this.cameraIndex].value,
  283. sourceType: ['album'],
  284. success: (res) => {
  285. let videoFile = res.tempFilePath;
  286. this.videoList = this.videoList.concat(videoFile)
  287. }
  288. })
  289. },
  290. chooseImage: async function () {
  291. if (this.imageList.length === 9) {
  292. let isContinue = await this.isFullImg();
  293. console.log("是否继续?", isContinue);
  294. if (!isContinue) {
  295. return;
  296. }
  297. }
  298. uni.chooseImage({
  299. sourceType: sourceType[this.sourceTypeIndex],
  300. sizeType: sizeType[this.sizeTypeIndex],
  301. count: this.imageList.length + this.count[this.countIndex] > 9 ? 9 - this.imageList.length : this.count[this.countIndex],
  302. success: (res) => {
  303. console.log(res)
  304. this.imageList = this.imageList.concat(res.tempFilePaths);
  305. }
  306. })
  307. },
  308. isFullImg: function () {
  309. return new Promise((res) => {
  310. uni.showModal({
  311. content: "已经有9张图片了,是否清空现有图片?",
  312. success: (e) => {
  313. if (e.confirm) {
  314. this.imageList = [];
  315. res(true);
  316. } else {
  317. res(false)
  318. }
  319. },
  320. fail: () => {
  321. res(false)
  322. }
  323. })
  324. })
  325. },
  326. previewImage: function (e) {
  327. var current = e.target.dataset.src
  328. // var current = 'https://i.loli.net/2019/02/18/5c6a6e2623448.jpg'
  329. // this.imageList = ['https://i.loli.net/2019/02/18/5c6a6e2623448.jpg','https://i.loli.net/2019/02/18/5c6a6e49829ea.jpg']
  330. console.log(current);
  331. console.log(this.imageList);
  332. uni.previewImage({
  333. current: current,
  334. urls: this.imageList
  335. })
  336. },
  337. touchStart: function (e) {
  338. this.startX = e.mp.changedTouches[0].pageX;
  339. },
  340. touchEnd: function (e) {
  341. this.endX = e.mp.changedTouches[0].pageX;
  342. if (this.endX - this.startX > 200) {
  343. uni.navigateBack();
  344. }
  345. }
  346. },
  347. onNavigationBarButtonTap (e) {
  348. if (e.index == 0) {
  349. this.publish();
  350. }
  351. },
  352. }
  353. </script>
  354. <style scoped>
  355. .showVedio {
  356. width: 100%;
  357. height: 100%;
  358. position: absolute;
  359. left: 0;
  360. right: 0;
  361. top: 0;
  362. bottom: 0;
  363. z-index: 300;
  364. }
  365. .cloneBut {
  366. position: relative;
  367. text-align: right;
  368. font-size: 24px;
  369. color: red;
  370. margin-left: 10px;
  371. margin-top: 10px;
  372. height: 30px;
  373. width: 30px;
  374. }
  375. .cloneBut-img {
  376. position: absolute;
  377. width: 30px;
  378. }
  379. .list_view {
  380. padding: 40upx;
  381. background: #ffffff;
  382. }
  383. .item_view {
  384. display: flex;
  385. height: 60upx;
  386. align-items: center;
  387. padding: 20upx 0;
  388. justify-content: space-between;
  389. }
  390. .cell-pd {
  391. padding: 20upx 30upx;
  392. }
  393. .uni-textarea {
  394. width: auto;
  395. padding: 20upx 25upx;
  396. line-height: 1.6;
  397. height: 150upx;
  398. }
  399. .uni-list::before {
  400. height: 0 !important;
  401. }
  402. .uni-list:after {
  403. height: 0;
  404. }
  405. .list-pd {
  406. margin-top: 0;
  407. }
  408. .close-view {
  409. text-align: center;
  410. line-height: 22upx;
  411. height: 24upx;
  412. width: 24upx;
  413. border-radius: 10px;
  414. background: #ef5350;
  415. color: #ffffff;
  416. position: absolute;
  417. top: 6upx;
  418. right: 8upx;
  419. font-size: 24upx;
  420. }
  421. .page {
  422. width: 750upx;
  423. height: 100%;
  424. }
  425. </style>