index.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <template>
  2. <view v-if="showPage">
  3. <view class="top-fixed" :style="'height:'+systems.barHeight+'rpx;'">
  4. <view :style="'height: '+systems.ktxStatusHeight+'rpx;'"></view>
  5. <view class="ddflex">
  6. <view class="back ddflex"
  7. :style="'height: '+systems.navigationHeight+'rpx;line-height: '+systems.navigationHeight+'rpx;'"
  8. @click="toBack">
  9. <image src="../static/images/back_black.png" mode="aspectFit"></image>
  10. </view>
  11. <view class="fflex" style="text-align: center;margin-left: rpx;"></view>
  12. </view>
  13. </view>
  14. <view :style="'height:'+systems.barHeight+'rpx;'"></view>
  15. <view class="ceng" v-if="isShowAdd" @click="isShowAdd = false"></view>
  16. <!-- click="isShowPreview = true" -->
  17. <view class="video dflex" @click="jumpUrl('/martial/videoPlay/index?code='+detaile.code+'&rootCode='+detaile.rootCode)">
  18. <image :src="detaile.pic" mode="aspectFit"></image>
  19. <image class="video-play" src="../static/images/m_play.png"></image>
  20. <!-- <video @click="isShowPreview = true"></video> -->
  21. </view>
  22. <view class="content">
  23. <view class="tit dflex">
  24. {{detaile.title}}
  25. </view>
  26. <view class="con">
  27. <rich-text :nodes="removeHtml(detaile.brief)"></rich-text>
  28. </view>
  29. <view class="pro" v-if="detaile.params.product">
  30. <view class="li ddflex" @click="jumpUrl('/product/detail/detail?id='+detaile.params.product.id)">
  31. <image :src="detaile.params.product.icon" mode="aspectFill" class="proimg"></image>
  32. <view class="fflex ddflex">
  33. <view class="proname fflex">{{detaile.params.product.title}}</view>
  34. <view class="ope dflex">
  35. <view class="ope-btn ddflex">视频同款</view>
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. <view class="bottom-info">
  42. <view class="bottom-info-browse">{{formatTime(detaile.createDate)}} 浏览 {{detaile.browseCount}}</view>
  43. <view style="margin-top: 20rpx;">
  44. <view class="ddflex">
  45. <image class="bottom-info-logo" :src="config.CONFIG_PROJECT_LOGO"></image>
  46. <view class="fflex">{{detaile.user&&detaile.user.nickName?detaile.user.nickName:config.CONFIG_PROJECT_TITLE}}</view>
  47. <view class="bottom-info-option" @click="showShare">
  48. <image style="width: 32rpx;height: 32rpx;margin: auto;" src="../static/images/share.png"></image>
  49. <view>分享</view>
  50. </view>
  51. <view class="bottom-info-option" style="margin-left: 50rpx;">
  52. <image v-if="!detaile.isThumbs" style="width: 32rpx;height: 32rpx;margin: auto;" src="../static/images/dz.png" @click="thumbs(true)"></image>
  53. <image v-if="detaile.isThumbs" style="width: 32rpx;height: 32rpx;margin: auto;" src="../static/images/dz_h.png" @click="thumbs(false)"></image>
  54. <view>{{detaile.thumbsCount?detaile.thumbsCount:0}}</view>
  55. </view>
  56. </view>
  57. </view>
  58. </view>
  59. <videoPreview v-if="isShowPreview" :material="detaile" :content="removeHtml(detaile.brief)" :src="detaile.params.video.playUrl" :product="detaile.params.product?detaile.params.product:null" @videoPreviewClose="videoPreviewClose" @videoPreviewClick="showShareVideo"></videoPreview>
  60. <!-- #ifdef H5 -->
  61. <view class="share-pop" @click="hideSharePop" v-if="isShowSharePop">
  62. <image src="../static/images/fx-tip1.png"></image>
  63. </view>
  64. <wx-share ref="wxshare" />
  65. <!-- #endif -->
  66. </view>
  67. </template>
  68. <script>
  69. const req = require('../../utils/request.js');
  70. const api = require('../../utils/api.js');
  71. const util = require('../../utils/util.js');
  72. var app = getApp();
  73. import videoPreview from '../components/videoPreview/index.vue';
  74. export default {
  75. components: {
  76. videoPreview
  77. },
  78. data() {
  79. return {
  80. systems: {},
  81. isTop: 0,
  82. isShowAdd: false,
  83. showPage:false,
  84. content: "",
  85. options:{},
  86. isShowShare: false,
  87. bottomPositon: '-100%',
  88. isShowPreview:false,
  89. previewIndex:0,
  90. isShowTs:false,
  91. code: '',
  92. rootCode: '',
  93. detaile:{},
  94. config:{},
  95. hideShare: true,
  96. isShowSharePop: false,
  97. };
  98. },
  99. async onLoad(options) {
  100. this.options = options
  101. if (options.appId) req.setStorage('appId', options.appId);
  102. if (options.x_code_id){
  103. options = await this.loadCodeParams(options.x_code_id)
  104. }
  105. this.PAGE_DATA_INIT_FN({
  106. BIND_ID:this.options.code
  107. })
  108. await req.silenceLogin(this.options.userId);
  109. this.code = options.code;
  110. this.rootCode = options.rootCode
  111. this.getConfig()
  112. await this.getDetail();
  113. },
  114. onReachBottom: function() {},
  115. onShareAppMessage: async function(options) {
  116. var content = await this.onShareMessage();
  117. this.SEND_SHARE_FN()
  118. return content;
  119. },
  120. onReady() {
  121. // #ifdef H5
  122. var that = this;
  123. //初始化分享内容
  124. setTimeout(async function() {
  125. var shareContent = await that.onShareMessage();
  126. if (shareContent) {
  127. shareContent.path = window.location.origin + shareContent.path;
  128. }
  129. that.$refs.wxshare.init(shareContent);
  130. }, 4 * 1000);
  131. // #endif
  132. },
  133. methods: {
  134. toBack() {
  135. let pages = getCurrentPages();
  136. if (pages.length > 1) {
  137. uni.navigateBack()
  138. }else{
  139. uni.switchTab({
  140. url:'/pages/tabBar/index'
  141. })
  142. }
  143. },
  144. async onShareMessage(options) {
  145. let isSolution = '';
  146. let path = '';
  147. // #ifndef H5
  148. isSolution = req.env[req.env.NODE_ENV].isSolution;
  149. // #endif
  150. // #ifdef H5
  151. isSolution = false;
  152. // #endif
  153. let userInfo = req.getStorage('userInfo');
  154. if (isSolution) {
  155. path = '/share/home/index?appId=' + req.getStorage('appId') + '&userId=' + req.getStorage(
  156. 'userInfo').id;
  157. } else {
  158. let page = getCurrentPages()
  159. let pageCurrent = page[page.length-1]
  160. path = pageCurrent.route+'?code=' + this.code + '&rootCode=' + this.rootCode + '&isShare=' + true + '&appId=' + req
  161. .getStorage('appId');
  162. // console.log(!req.getStorage('userInfo').id);
  163. if (!userInfo.id) {} else {
  164. path += '&userId=' + userInfo.id;
  165. }
  166. path = this.SHARE_BEHAVIOR_FN({path:path,sendShare:false}).path
  167. }
  168. console.log({
  169. title: this.detaile.title,
  170. imageUrl: this.detaile.pic,
  171. path: path
  172. })
  173. return {
  174. title: this.detaile.title,
  175. imageUrl: this.detaile.pic,
  176. path: path
  177. };
  178. },
  179. showShare() {
  180. console.log(11111)
  181. // #ifdef H5
  182. this.hideShare = false;
  183. this.showSharePop();
  184. console.log('引导分享==')
  185. // #endif
  186. },
  187. showSharePop() {
  188. this.isShowSharePop = true;
  189. },
  190. hideSharePop() {
  191. this.isShowSharePop = false;
  192. },
  193. closePop(){
  194. this.isShowAdd = false
  195. },
  196. jumpUrl(url){
  197. this.isShowAdd = false
  198. uni.navigateTo({
  199. url:url
  200. })
  201. },
  202. getConfig() {
  203. req.getRequest('/api/config', {}, res => {
  204. this.config = res
  205. })
  206. },
  207. removeHtml(text) {
  208. text = text.replace(/\r\n/g, "<br>")
  209. text = text.replace(/\n/g, "<br>");
  210. text = text.replace(/↵/g, "<br>");
  211. return text
  212. },
  213. removeText(text) {
  214. text = text.replace(/<br\/>/g, "\r\n")
  215. text = text.replace(/<br>/g, "\r\n")
  216. return text
  217. },
  218. getDetail() {
  219. let that = this;
  220. let apiUrl = '/api/v3/material/library/detail';
  221. return new Promise((resolve,reject)=>{
  222. req.getRequest(apiUrl,{ code: that.code },async res => {
  223. that.detaile = res;
  224. that.showPage = true
  225. resolve();
  226. },true);
  227. })
  228. },
  229. videoPreviewClose(){
  230. this.isShowPreview = false
  231. },
  232. showShareVideo(){
  233. this.isShowShare = true
  234. this.bottomPositon = 0
  235. },
  236. hideShareVideo(){
  237. this.isShowShare = false
  238. this.bottomPositon = '-100%'
  239. },
  240. formatTime(time){
  241. let date = new Date(time.replace(/-/g,'/'))
  242. return util.formatTimeComm(date,'Y.M.D')
  243. },
  244. loadCodeParams(scene) {
  245. let _ts = this;
  246. return new Promise((resolve, reject) => {
  247. let form = {
  248. scene: scene
  249. };
  250. if (!scene) {
  251. resolve();
  252. return false;
  253. }
  254. req.getRequest('/api/code/params', form, data => {
  255. let res = JSON.parse(data.scene)
  256. for(let key in res){
  257. this.options[key] = res[key]
  258. }
  259. resolve(res);
  260. });
  261. });
  262. },
  263. thumbs(type){
  264. if(req.isLogins(true)){
  265. if(type){//点赞
  266. this.SEND_COLLECT_FN({IS_THUMBS:true})
  267. this.detaile.isThumbs = true
  268. this.detaile.thumbsCount++
  269. }else{//取消点赞
  270. this.SEND_COLLECT_FN({IS_THUMBS:false})
  271. this.detaile.isThumbs = false
  272. this.detaile.thumbsCount--
  273. }
  274. }
  275. },
  276. },
  277. mounted() {
  278. const systemInfo = uni.getSystemInfoSync();
  279. // px转换到rpx的比例
  280. let pxToRpxScale = 750 / systemInfo.windowWidth;
  281. let systems = {
  282. ktxStatusHeight: systemInfo.statusBarHeight * pxToRpxScale, // 状态栏的高度
  283. navigationHeight: 44 * pxToRpxScale // 导航栏的高度
  284. };
  285. systems.barHeight = systems.ktxStatusHeight + systems.navigationHeight;
  286. this.systems = systems;
  287. },
  288. };
  289. </script>
  290. <style>
  291. @import './index.css';
  292. </style>