hqs-popup.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  1. <style lang="scss">
  2. .hqs-popup {
  3. z-index: 999999;
  4. .hidden { visibility: hidden; }
  5. .qs-side {
  6. min-width: 60px;
  7. padding: 15px 20px 10rpx;
  8. color: #888;
  9. flex-shrink: 0;
  10. &:active { opacity: .8; }
  11. }
  12. }
  13. @import 'player.scss';
  14. </style>
  15. <template>
  16. <uni-popup ref="popup"
  17. :mask-click="maskClick" @change="onChange"
  18. :type="from" class="hqs-popup">
  19. <view class="qs-con"
  20. :style="conStyle"
  21. @mousedown="onTouch" @mousemove="onTouch" @mouseup="onTouch"
  22. @touchstart="onTouch" @touchmove="onTouch" @touchend="onTouch">
  23. <view class="topBody">
  24. </view>
  25. <view class="play_header">
  26. <view class="bar">
  27. <view class="left" @click="close();">
  28. <image class="backup" mode="widthFix" src="../../static/icon/play_music_close_img.png"></image>
  29. </view>
  30. <view class="downline">
  31. 当前播放
  32. </view>
  33. <view class="right" @click="collectionIt('story',storyInfo.id)"><!-- @click="share_this = true"-->
  34. <!-- <image class="backup" mode="widthFix" src="../../static/icon/ic_share_black.png" style="opacity: 0;"></image> -->
  35. <image class="backup" mode="widthFix" src="../../static/icon/ic_coll_no.png" v-if="!collection_story"></image>
  36. <image class="backup" mode="widthFix" src="../../static/icon/ic_coll_yes.png" v-else></image>
  37. </view>
  38. </view>
  39. </view>
  40. <view class="yuanjiao">
  41. </view>
  42. <view class="contBody">
  43. <view class="img">
  44. <image class="iconStop" mode="widthFix" :src="storyInfo.image" v-if="!isPlayingState"></image>
  45. <image class="iconPlay" mode="widthFix" :src="storyInfo.image" v-else></image>
  46. </view>
  47. <view class="title">
  48. {{storyInfo.title}}
  49. </view>
  50. </view>
  51. <view class="playSlider">
  52. <slider :value="playSliderNum" @change="sliderChange" @changing="sliderChanging" activeColor="#ff6b4d" backgroundColor="#cbcbcb80" block-color="#ff4845" block-size="12" />
  53. </view>
  54. <view class="playSlider2">
  55. <view class="left">{{convertSecondsToMinutesSeconds(currentTime)}}</view>
  56. <view class="right">{{convertSecondsToMinutesSeconds(durationTime)}}</view>
  57. </view>
  58. <view class="control">
  59. <view class="loop" @click="SetLoopType()">
  60. <image class="icon" mode="widthFix" src="../../static/icon/ic_list.png"></image>
  61. <text class="num" v-if="isLoopOne">1</text>
  62. </view>
  63. <view class="last" @click="playLastNext('last')">
  64. <image class="icon" mode="widthFix" src="../../static/icon/ic_play_music_last_on.png"></image>
  65. </view>
  66. <view class="play" @click="playOrPause">
  67. <image class="iconP" mode="widthFix" src="../../static/icon/ic_play_music_play.png" v-if="!isPlayingState"></image>
  68. <image class="iconP" mode="widthFix" src="../../static/icon/ic_play_music_pause.png" v-else></image>
  69. </view>
  70. <view class="next" @click="playLastNext('next')">
  71. <image class="icon" mode="widthFix" src="../../static/icon/ic_play_music_next_on.png"></image>
  72. </view>
  73. <view class="plist" @click="showStoryList = true;">
  74. <image class="icon" mode="widthFix" src="../../static/icon/ic_play_music_list_on.png"></image>
  75. </view>
  76. </view>
  77. <view class="blankHei"></view>
  78. <view class="bgAlpha" v-if="shopPlayTime" @click="shopPlayTime = false"></view>
  79. <view class="pop_time" v-if="shopPlayTime">
  80. <view class="close" @click="shopPlayTime = false"><image class="icon" mode="widthFix" src="../../static/icon/ic_close.png"></image></view>
  81. <view class="title">按时长</view>
  82. <view class="list">
  83. <view class="item" v-for="(item,index2) in time1_list" :key="index2" @click="selTimer(1,index2)" :class="time_sel1==index2?'active':''">
  84. <text>{{item.name}}</text>
  85. </view>
  86. </view>
  87. <view class="title">按集数</view>
  88. <view class="list">
  89. <view class="item" v-for="(item,index2) in 10" :key="index2" @click="selTimer(2,index2)" :class="time_sel2==index2?'active':''">
  90. <text>{{index2+1}}集</text>
  91. </view>
  92. </view>
  93. </view>
  94. <view class="pop_story_list" v-if="showStoryList">
  95. <view class="content">
  96. <image class="close" mode="widthFix" src="../../static/icon/ic_close.png" @click="showStoryList = false;"></image>
  97. <view class="title">播放列表</view>
  98. <view class="story_list2">
  99. <scroll-view style="width: 100%; height: 43vh;" :scroll-y="true">
  100. <!-- #ifdef APP-NVUE -->
  101. <list>
  102. <cell>
  103. <!-- #endif -->
  104. <view class="item" @click="playIt2(item)" v-for="(item,index2) in StoryList" :key="index2" style="overflowY:auto;">
  105. <view class="imgR">
  106. <image class="icon" mode="widthFix" :src="item.image"></image>
  107. <view class="play" v-if="false"><image class="img" mode="widthFix" src="../../static/icon/story_detail_video_stop.png"></image></view>
  108. </view>
  109. <view class="right">
  110. <view class="title1">{{item.title}}</view>
  111. <view class="desc">{{item.introduction}}</view>
  112. <view class="stat">
  113. <view class="stat1"><image class="img1" mode="widthFix" src="../../static/icon/ic_view.png"></image> {{item.view_num}}</view>
  114. <!-- <view class="line"></view> -->
  115. <view class="stat1"><image class="img1" mode="widthFix" src="../../static/icon/ic_time.png"></image> {{item.duration}}</view>
  116. </view>
  117. </view>
  118. <view class="replay" v-if="item.istry > 0 && false">
  119. 试听
  120. </view>
  121. </view>
  122. <!-- #ifdef APP-NVUE -->
  123. </cell>
  124. </list>
  125. <!-- #endif -->
  126. </scroll-view>
  127. </view>
  128. </view>
  129. </view>
  130. <slot name="sub-header"></slot>
  131. <scroll-view
  132. @scroll="onScroll">
  133. <view>
  134. <slot></slot>
  135. </view>
  136. </scroll-view>
  137. <slot name="bottom"></slot>
  138. </view>
  139. </uni-popup>
  140. </template>
  141. <script>
  142. import UniPopup from './uni-popup.vue'
  143. import pubc from '@/common/public.js'
  144. export default {
  145. components: {
  146. UniPopup,
  147. },
  148. props: {
  149. // 弹窗显示可通过v-model控制
  150. value: Boolean,
  151. // 弹窗打开开始方向
  152. from: {
  153. type: String,
  154. default: 'bottom',
  155. },
  156. // storyInfo: {
  157. // type: Object,
  158. // default () {
  159. // return {}
  160. // }
  161. // },
  162. // 内容区边缘圆角大小
  163. round: {
  164. type: Number,
  165. default: 10,
  166. },
  167. // 弹窗内容宽度(当from=left或right时起作用)
  168. width: {
  169. type: String,
  170. default: '60vw',
  171. },
  172. // 弹窗内容高度(当from=top或bottom时起作用)
  173. height: {
  174. type: String,
  175. default: '100vh',
  176. },
  177. // 显示默认头部标题栏(仅在底部弹出时有)
  178. showHeader: {
  179. type: Boolean,
  180. default: true,
  181. },
  182. // 弹窗标题
  183. title: String,
  184. // 显示左侧(返回)按钮,如果v-slot:back存在时,也会显示此按钮
  185. showBack: Boolean,
  186. // 显示关闭按钮,如果是字符串,将作为uview(需另外引入)的u-icon组件的name(如showClose="close",会显示close图标)
  187. showClose: {
  188. type: [Boolean, String],
  189. default: true,
  190. },
  191. // 是否可点击模态背景关闭弹窗
  192. maskClick: {
  193. type: Boolean,
  194. default: true,
  195. },
  196. },
  197. data() {
  198. return {
  199. scrollTop: 0,
  200. panStyle: '',
  201. showPopup: false,
  202. cate_id:0,
  203. StoryCate:{},
  204. StoryList:[],
  205. collection_theme:'false',
  206. collection_story:'false',
  207. story: {
  208. title:'----------------------',
  209. id:0
  210. },
  211. storyInfo:{},
  212. current:0,
  213. offsetY: 0,
  214. share_this:false,
  215. scrollEnabled: true, // 控制item的滚动
  216. showPlay:false,
  217. shopPlayTime:false,
  218. showStoryList:false,
  219. time_sel1:0,
  220. time_sel2:-1,
  221. overflowh:'auto',
  222. currentTime: 0, // 用于存储当前播放进度
  223. durationTime:0,
  224. playSliderNum:0,
  225. time1_list:[
  226. {name:'不限时',time:0},
  227. {name:'10分钟',time:10},
  228. {name:'20分钟',time:20},
  229. {name:'30分钟',time:30},
  230. {name:'40分钟',time:40},
  231. {name:'50分钟',time:50},
  232. {name:'60分钟',time:60}
  233. ],
  234. isPlayingState:false,
  235. isChangeSlider:false,
  236. isLoopOne:false,
  237. }
  238. },
  239. computed: {
  240. closeIcon() {
  241. if(typeof this.showClose == 'string') return this.showClose
  242. return false
  243. },
  244. isVertical() {
  245. return ['bottom', 'top'].includes(this.from)
  246. },
  247. conStyle() {
  248. return ""
  249. },
  250. },
  251. onLoad() {
  252. },
  253. watch: {
  254. value(val) {
  255. console.log("watch",val);
  256. if(val == this.showPopup) return
  257. if(val) this.open()
  258. else this.close()
  259. },
  260. showPopup(val) {
  261. // this.$emit('input', val)
  262. },
  263. },
  264. created() {
  265. uni.$on('info', (data)=>{
  266. console.log("on-info",data);
  267. this.storyInfo = data;
  268. })
  269. uni.$on('isplay', (data)=>{
  270. console.log("isplay:",data);
  271. this.isPlayingState = data.isplay;
  272. })
  273. },
  274. mounted() {
  275. if(this.value) this.open()
  276. let that = this;
  277. try {
  278. this.$audio.onTimeUpdate(() => {
  279. that.currentTime = that.$audio.currentTime;
  280. that.durationTime = that.$audio.duration;
  281. if(!that.isChangeSlider) {
  282. that.playSliderNum = (that.$audio.currentTime / that.$audio.duration) * 100;
  283. }
  284. // console.log("this.durationTime",this.durationTime + ";" + this.playSliderNum);
  285. });
  286. } catch (e) {
  287. } finally {
  288. }
  289. },
  290. beforeDestroy() {
  291. try {
  292. // 在组件销毁前移除事件监听器
  293. this.$audio.offTimeUpdate();
  294. } catch (e) {
  295. } finally {
  296. }
  297. },
  298. methods: {
  299. onScroll(e) {
  300. this.scrollTop = e.detail.scrollTop
  301. },
  302. onTouch(ev) {
  303. // if(!this.maskClick) return
  304. const { pageX, pageY } = ev.changedTouches[0] || ev
  305. if(['touchstart', 'mousedown'].includes(ev.type)) {
  306. this.startX = pageX
  307. this.startY = pageY
  308. this.startTime = ev.timeStamp
  309. } else {
  310. if(!this.startTime) return
  311. const orien = this.isVertical ? 'Y' : 'X'
  312. let moveDis = pageY - this.startY
  313. if(this.from == 'left') moveDis = this.startX - pageX
  314. else if(this.from == 'right') moveDis = pageX - this.startX
  315. else if(this.from == 'top') moveDis = -moveDis
  316. if(!this.maskClick) moveDis /= 3
  317. const duration = (ev.timeStamp - this.startTime)
  318. const speed = moveDis/duration
  319. if(['touchend', 'mouseup'].includes(ev.type)) {
  320. if(this.panStyle) {
  321. if(this.maskClick && (moveDis > 120 || speed > 0.25)) {
  322. this.close()
  323. }
  324. else {
  325. this.panStyle = `transform: translate${orien}(0); transition: all ease 200ms;`
  326. }
  327. setTimeout(() => {
  328. this.panStyle = ''
  329. }, 300)
  330. }
  331. // conScrollTop = 0
  332. this.startTime = 0
  333. return
  334. }
  335. // if(this.scrollTop > 0) return
  336. if(moveDis > 0) {
  337. if(this.from == 'left' || this.from == 'top') moveDis *= -1
  338. this.panStyle = `transform: translate${orien}(${moveDis}px); transition: none;`
  339. }
  340. }
  341. },
  342. onChange({ show }) {
  343. this.showPopup = show
  344. },
  345. open() {
  346. this.$refs.popup.open()
  347. this.showPopup = true;
  348. let plstory = uni.getStorageSync('playing_story_to');
  349. if(plstory) {
  350. this.storyInfo = JSON.parse(plstory);
  351. }
  352. this.playItStart();
  353. },
  354. close() {
  355. this.$refs.popup.close();
  356. this.showPopup = false;
  357. uni.$emit('closePop')
  358. },
  359. onBack() {
  360. this.$emit('back')
  361. },
  362. playItStart() {
  363. console.log("playIt",this.storyInfo);
  364. if(this.storyInfo.id > 0) {
  365. this.$nextMax = 0;//初始化集数
  366. this.$nextMaxTime = 0;//初始化时长
  367. this.offsetY = 0;
  368. let plstory = uni.getStorageSync('playing_story');
  369. if(plstory) {
  370. this.story = JSON.parse(plstory);
  371. }
  372. this.$audio.singer = '故事花园';
  373. this.$audio.lrc = '';
  374. this.$audio.coverImgUrl = this.storyInfo.image;
  375. this.$audio.pre_url = this.storyInfo.filename;
  376. this.$audio.title = this.storyInfo.title;
  377. this.$audio.epname = this.storyInfo.cate_name;
  378. this.$audio.src = this.storyInfo.filename;
  379. // console.log("item",item.story_id);
  380. console.log("this.story.story_id",this.story.story_id);
  381. let fileNow = "";
  382. if(this.storyInfo.story_id == this.story.story_id) {
  383. this.showPlay = true;
  384. fileNow = pubc.Decrypt(this.storyInfo.filename);
  385. console.log("filename",this.storyInfo.filename);
  386. console.log("Decrypt",fileNow);
  387. // fileNow = "https://duoxiaoduoxue.com/media/mp3/6473.mp3";
  388. this.$audio.src = fileNow;
  389. // if(this.$audio.poused) {
  390. // this.$audio.play();
  391. // }
  392. // this.$audio.play();
  393. this.isPlaying();
  394. }else {
  395. this.showPlay = true;
  396. // console.log("play-pubc",item);
  397. fileNow = pubc.Decrypt(this.storyInfo.filename);
  398. console.log("filename",this.storyInfo.filename);
  399. console.log("Decrypt",fileNow);
  400. // fileNow = "https://duoxiaoduoxue.com/media/mp3/6473.mp3";
  401. // this.overflowh = 'hidden';
  402. this.$audio.src = fileNow;
  403. this.$audio.play();
  404. this.isPlaying();
  405. }
  406. this.isCollection("story",this.storyInfo.story_id);
  407. this.storyInfo.filename = fileNow;
  408. // this.story = item;
  409. this.cate_id = this.storyInfo.cate_id;
  410. // this.$musicInfo.title = '音乐标题';
  411. // backgroundAudioManager.epname = '专辑名称';
  412. // backgroundAudioManager.singer = '演唱者';
  413. // backgroundAudioManager.coverImgUrl = '封面图片地址'; // 推荐本地路径
  414. // backgroundAudioManager.src = '音乐文件地址';
  415. console.log("this.musicInfo",this.$musicInfo);
  416. let self = this;
  417. let dataString = uni.getStorageSync('story_list_all_' + this.storyInfo.cate_id);
  418. if(dataString) {
  419. let dataMsg = JSON.parse(dataString);
  420. this.StoryCate = dataMsg.StoryCate;
  421. this.StoryList = dataMsg.story;
  422. }else {
  423. this.loadData(1);
  424. }
  425. let that = this;
  426. setTimeout(function() {
  427. that.historyIt(that.storyInfo.story_id);
  428. },2000)
  429. let dataStringPlay = JSON.stringify(this.storyInfo);
  430. uni.setStorageSync('playing_story', dataStringPlay);
  431. }
  432. },
  433. handleChildBtnClick(event) {
  434. event.stopPropagation(); // 阻止事件冒泡
  435. console.log('子按钮被点击');
  436. },
  437. doNothing() {
  438. event.stopPropagation(); // 阻止事件冒泡
  439. console.log('子按钮被点击');
  440. },
  441. init() {
  442. this.offsetY = 0;
  443. this.showPlay = true;
  444. },
  445. SetLoopType() {
  446. if(this.isLoopOne) {
  447. this.isLoopOne = false;
  448. let nxt = {
  449. next1:0,
  450. next2:0
  451. }
  452. this.isLoopOne = true;
  453. uni.setStorageSync('next', nxt);
  454. }else {
  455. let nxt = {
  456. next1:0,
  457. next2:1
  458. }
  459. this.isLoopOne = true;
  460. uni.setStorageSync('next', nxt);
  461. }
  462. },
  463. selTimer(type,index) {
  464. if(type == 1) {
  465. this.time_sel1 = index
  466. this.time_sel2 = -1
  467. this.$nextMax = 0;
  468. this.$nextMaxTime = index * 10;
  469. }else if(type == 2) {
  470. this.time_sel2 = index
  471. this.time_sel1 = -1
  472. this.$nextMax = index + 1;
  473. this.$nextMaxTime = 0;
  474. }
  475. this.shopPlayTime = false;
  476. },
  477. // onChange(e) {
  478. // this.current = e.detail.current;
  479. // },
  480. convertSecondsToMinutesSeconds(seconds) {
  481. if(seconds > 0) {
  482. seconds = parseInt(seconds);
  483. var minutes = Math.floor(seconds / 60);
  484. var remainingSeconds = seconds % 60;
  485. return (minutes<10?'0'+minutes:minutes) + ":" + (remainingSeconds<10?'0'+remainingSeconds:remainingSeconds) + "";
  486. }else {
  487. return '00:00';
  488. }
  489. },
  490. playLastNext(type) {
  491. let dataString = uni.getStorageSync('story_list_all_' + this.storyInfo.cate_id);
  492. if(dataString) {
  493. let dataMsg = JSON.parse(dataString);
  494. let StoryList = dataMsg.story;
  495. let useNext = 0;
  496. let storyNext = '';
  497. if(type == 'last') {
  498. for (const item of StoryList) {
  499. if(parseInt(item.id) == parseInt(this.storyInfo.id)) {
  500. break;
  501. }
  502. storyNext = item;
  503. }
  504. }else {
  505. for (const item of StoryList) {
  506. if(useNext > 0) {
  507. storyNext = item;
  508. break;
  509. }
  510. // console.log("itemID:",parseInt(item.id) + "," + parseInt(story.id));
  511. if(parseInt(item.id) == parseInt(this.storyInfo.id)) {
  512. useNext = 1;
  513. }
  514. }
  515. }
  516. if(storyNext != "") {
  517. this.playIt2(storyNext);
  518. }
  519. }
  520. },
  521. playIt2(item) {
  522. this.offsetY = 0;
  523. this.story.title = item.title;
  524. item.story_id = item.id;
  525. this.story = item;
  526. this.isCollection("story",item.id);
  527. let that = this;
  528. setTimeout(function() {
  529. that.historyIt(that.story.story_id);
  530. },2000)
  531. this.storyInfo = item;
  532. this.$audio.singer = '故事花园';
  533. this.$audio.lrc = '';
  534. this.$audio.coverImgUrl = this.storyInfo.image;
  535. this.$audio.pre_url = this.storyInfo.filename;
  536. this.$audio.title = this.storyInfo.title;
  537. this.$audio.epname = this.storyInfo.cate_name;
  538. let fileNow = pubc.Decrypt(item.filename);
  539. console.log("filename",item.filename);
  540. console.log("Decrypt",fileNow);
  541. // fileNow = "https://duoxiaoduoxue.com/media/mp3/6473.mp3";
  542. // this.overflowh = 'hidden';
  543. this.$audio.src = fileNow;
  544. this.$audio.play();
  545. this.showStoryList = false;
  546. let dataStringPlay = JSON.stringify(this.story);
  547. uni.setStorageSync('playing_story', dataStringPlay);
  548. // let dataString = uni.getStorageSync('story_list_' + item.cate_id);
  549. // if(dataString) {
  550. // let dataMsg = JSON.parse(dataString);
  551. // this.StoryCate = dataMsg.StoryCate;
  552. // this.StoryList = dataMsg.story;
  553. // }else {
  554. // this.loadData(1);
  555. // }
  556. },
  557. playOrPause() {
  558. console.log("----playOrPause");
  559. try {
  560. if(this.$audio.paused) {
  561. this.isPlayingState = true;
  562. this.$audio.play();
  563. }else {
  564. this.isPlayingState = false;
  565. this.$audio.pause();
  566. }
  567. } catch (e) {
  568. // error
  569. }
  570. },
  571. isPlaying() {
  572. try {
  573. if(this.$audio.paused) {
  574. this.isPlayingState = false;
  575. }else {
  576. this.isPlayingState = true;
  577. }
  578. } catch (e) {
  579. // error
  580. }
  581. return !this.$audio.paused;
  582. },
  583. sliderChange(e) {
  584. console.log('value 发生变化:' + e.detail.value)
  585. let toTime = this.$audio.duration * e.detail.value / 100;
  586. // 计算目标播放时间(秒)
  587. // let targetTime = this.$audio.duration * 0.38;
  588. // 跳转到目标播放时间
  589. this.$audio.pause();
  590. this.$audio.seek(toTime);
  591. let that = this;
  592. setTimeout(function() {
  593. that.isChangeSlider = false;
  594. that.$audio.play();
  595. },200);
  596. // this.playSliderNum = (this.$audio.currentTime / this.$audio.duration) * 100;
  597. // this.$audio.
  598. },
  599. sliderChanging(e) {
  600. this.isChangeSlider = true;
  601. },
  602. collectionIt(type,tid) {
  603. console.log("collectionIt");
  604. let obj2 = {
  605. cate_id:parseInt(tid)
  606. }
  607. if(type == 'story') {
  608. obj2 = {
  609. story_id:parseInt(tid)
  610. }
  611. }
  612. const postData = Object.assign({}, getApp().globalData.postHeader, obj2);
  613. console.log(postData);
  614. let self = this;
  615. uni.request({
  616. url: this.$apiHost + '/Member/collection_edit', //仅为示例,并非真实接口地址。
  617. data: postData,
  618. method:'POST',
  619. header: {
  620. 'content-type': 'application/json' ,//自定义请求头信息
  621. 'Access-Control-Allow-Origin':'*'
  622. },
  623. success: (res) => {
  624. console.log('data:', res.data);
  625. uni.showToast({
  626. title: res.data.msg
  627. });
  628. this.isCollection(type,tid)
  629. }
  630. });
  631. },
  632. loadData(is_first) {
  633. console.log("this.globalData",getApp().globalData);
  634. let obj2 = {
  635. cate_id:""+this.cate_id+"",
  636. is_first:is_first
  637. }
  638. const postData = Object.assign({}, getApp().globalData.postHeader, obj2);
  639. console.log(postData);
  640. let self = this;
  641. uni.request({
  642. url: this.$apiHost + '/Story/list', //仅为示例,并非真实接口地址。
  643. data: postData,
  644. method:'POST',
  645. header: {
  646. 'content-type': 'application/json' ,//自定义请求头信息
  647. 'Access-Control-Allow-Origin':'*'
  648. },
  649. success: (res) => {
  650. console.log('data:', res.data);
  651. if(is_first == 0) {
  652. let dataString = JSON.stringify(res.data.msg);
  653. uni.setStorageSync('story_list_' + this.cate_id, dataString);
  654. }else if(is_first == 1) {
  655. this.StoryCate = res.data.msg.StoryCate;
  656. this.StoryList = res.data.msg.story;
  657. if(res.data.status) {
  658. setTimeout(function() {
  659. self.loadData(2);
  660. },1000);
  661. }
  662. }else if(is_first == 2) {
  663. this.StoryList = this.StoryList.concat(res.data.msg.story);
  664. let obj2 = {
  665. StoryCate:this.StoryCate,
  666. story:this.StoryList
  667. }
  668. let dataString = JSON.stringify(obj2);
  669. // console.log('dataString2:', dataString);
  670. uni.setStorageSync('story_list_all_' + this.cate_id, dataString);
  671. }
  672. }
  673. });
  674. },
  675. isCollection(type,tid) {
  676. let obj2 = {
  677. type:""+type+"",
  678. cate_id:parseInt(tid)
  679. }
  680. if(type == 'story') {
  681. obj2 = {
  682. type:""+type+"",
  683. story_id:parseInt(tid)
  684. }
  685. }
  686. const postData = Object.assign({}, getApp().globalData.postHeader, obj2);
  687. let self = this;
  688. uni.request({
  689. url: this.$apiHost + '/Story/isFavorite', //仅为示例,并非真实接口地址。
  690. data: postData,
  691. method:'POST',
  692. header: {
  693. 'content-type': 'application/json' ,//自定义请求头信息
  694. 'Access-Control-Allow-Origin':'*'
  695. },
  696. success: (res) => {
  697. console.log('isCollection:', res.data);
  698. if(type == 'story') {
  699. this.collection_story = res.data.status;
  700. }else {
  701. this.collection_theme = res.data.status;
  702. }
  703. console.log("this.collection_theme",this.collection_theme);
  704. }
  705. });
  706. },
  707. historyIt(tid) {
  708. let obj2 = {
  709. story_id:parseInt(tid)
  710. }
  711. const postData = Object.assign({}, getApp().globalData.postHeader, obj2);
  712. console.log(postData);
  713. let self = this;
  714. uni.request({
  715. url: this.$apiHost + '/Member/history_edit', //仅为示例,并非真实接口地址。
  716. data: postData,
  717. method:'POST',
  718. header: {
  719. 'content-type': 'application/json' ,//自定义请求头信息
  720. 'Access-Control-Allow-Origin':'*'
  721. },
  722. success: (res) => {
  723. console.log('historyIt:', res.data);
  724. }
  725. });
  726. },
  727. }
  728. }
  729. </script>