index.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. <template>
  2. <view>
  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. <view class="file-box">
  17. <image class="file-icon" src="../static/images/m_pdf.png" mode="widthFix"></image>
  18. <view class="file-title">{{detaile.params&&detaile.params.brief?JSON.parse(detaile.params.brief).title:detaile.brief}}</view>
  19. <view class="file-size">文件大小:{{detaile.params&&detaile.params.brief?(JSON.parse(detaile.params.brief).size/1024/1024).toFixed(2)+'MB':'未知'}}</view>
  20. <view class="file-down" @click="downloadFile(detaile.brief)">下载文档</view>
  21. </view>
  22. <view class="bottom-fixed" v-if="cardInfo">
  23. <view class="ddflex card-box" @click="jumpUrl('/card/index/index?cardId='+cardInfo.id)">
  24. <image class="card-header" :src="cardInfo.imageMap?cardInfo.imageMap:'../../static/pages/images/userimg.png'"></image>
  25. <view class="fflex">
  26. <view class="card-name">{{cardInfo.realName}}</view>
  27. <view class="card-phone">{{cardInfo.phone}}</view>
  28. </view>
  29. <view class="card-line"></view>
  30. <view class="card-btn">联系TA</view>
  31. </view>
  32. </view>
  33. <!-- #ifdef H5 -->
  34. <view class="share-pop" @click="hideSharePop" v-if="isShowSharePop">
  35. <image src="../static/images/fx-tip1.png"></image>
  36. </view>
  37. <wx-share ref="wxshare" />
  38. <!-- #endif -->
  39. </view>
  40. </template>
  41. <script>
  42. const app = getApp();
  43. const req = require("../../utils/request.js");
  44. const api = require('../../utils/api.js');
  45. export default {
  46. components: {},
  47. props: {},
  48. data() {
  49. return {
  50. picUrlss: req.public.picUrls,
  51. systems: {},
  52. isTop: 0,
  53. isShowAdd: false,
  54. code: '',
  55. rootCode: '',
  56. detaile: {},
  57. isShowShare: false,
  58. bottomPositon: '-100%',
  59. cardInfo:'',
  60. hideShare: true,
  61. isShowSharePop: false,
  62. }
  63. },
  64. async onLoad(options) {
  65. this.options = options
  66. if (options.appId) req.setStorage('appId', options.appId);
  67. if (options.x_code_id){
  68. options = await this.loadCodeParams(options.x_code_id)
  69. }
  70. this.PAGE_DATA_INIT_FN({
  71. BIND_ID:this.options.code
  72. })
  73. await req.silenceLogin();
  74. this.code = options.code;
  75. this.rootCode = options.rootCode
  76. await this.getDetail();
  77. if(this.options.userId)
  78. this.getCardInfo()
  79. },
  80. onShow() {
  81. if(this.options.userId)
  82. this.getCardInfo()
  83. },
  84. onShareAppMessage: async function(options) {
  85. var content = await this.onShareMessage();
  86. this.SEND_SHARE_FN()
  87. return content;
  88. },
  89. onReady() {
  90. // #ifdef H5
  91. var that = this;
  92. //初始化分享内容
  93. setTimeout(async function() {
  94. var shareContent = await that.onShareMessage();
  95. if (shareContent) {
  96. shareContent.path = window.location.origin + shareContent.path;
  97. }
  98. that.$refs.wxshare.init(shareContent);
  99. }, 4 * 1000);
  100. // #endif
  101. },
  102. methods: {
  103. toBack() {
  104. let pages = getCurrentPages();
  105. if (pages.length > 1) {
  106. uni.navigateBack()
  107. }else{
  108. uni.switchTab({
  109. url:'/pages/tabBar/index'
  110. })
  111. }
  112. },
  113. async onShareMessage(options) {
  114. let isSolution = '';
  115. let path = '';
  116. // #ifndef H5
  117. isSolution = req.env[req.env.NODE_ENV].isSolution;
  118. // #endif
  119. // #ifdef H5
  120. isSolution = false;
  121. // #endif
  122. let userInfo = req.getStorage('userInfo');
  123. if (isSolution) {
  124. path = '/share/home/index?appId=' + req.getStorage('appId') + '&userId=' + req.getStorage(
  125. 'userInfo').id;
  126. } else {
  127. let page = getCurrentPages()
  128. let pageCurrent = page[page.length-1]
  129. path = pageCurrent.route+'?code=' + this.code + '&rootCode=' + this.rootCode + '&isShare=' + true + '&appId=' + req
  130. .getStorage('appId');
  131. // console.log(!req.getStorage('userInfo').id);
  132. if (!userInfo.id) {} else {
  133. path += '&userId=' + userInfo.id;
  134. }
  135. path = this.SHARE_BEHAVIOR_FN({path:path,sendShare:false}).path
  136. }
  137. console.log({
  138. title: this.detaile.title,
  139. imageUrl: this.detaile.pic,
  140. path: path
  141. })
  142. return {
  143. title: this.detaile.title,
  144. imageUrl: this.detaile.pic,
  145. path: path
  146. };
  147. },
  148. showShare() {
  149. // console.log(11111,this.hideShare)
  150. // #ifdef H5
  151. this.hideShare = false;
  152. this.showSharePop();
  153. console.log('引导分享==')
  154. // #endif
  155. },
  156. showSharePop() {
  157. this.isShowSharePop = true;
  158. },
  159. hideSharePop() {
  160. this.isShowSharePop = false;
  161. },
  162. closePop(){
  163. this.isShowAdd = false
  164. },
  165. jumpUrl(url){
  166. this.isShowAdd = false
  167. uni.navigateTo({
  168. url:url
  169. })
  170. },
  171. getDetail() {
  172. let that = this;
  173. let apiUrl = '/api/v3/material/library/detail';
  174. return new Promise((resolve, reject) => {
  175. req.getRequest(apiUrl, {
  176. code: that.code
  177. }, res => {
  178. that.detaile = res;
  179. // #ifdef APP-PLUS
  180. // that.downloadFile(that.detaile.brief)
  181. // #endif
  182. resolve();
  183. }, true);
  184. })
  185. },
  186. downloadFile(url) {
  187. let that = this
  188. uni.showLoading({
  189. title:'加载中'
  190. })
  191. // #ifdef APP-PLUS
  192. uni.downloadFile({
  193. url: url,
  194. success: function(res) {
  195. uni.hideLoading()
  196. let filepathss = res.tempFilePath
  197. filepathss = plus.io.convertLocalFileSystemURL(res.tempFilePath);
  198. uni.openDocument({
  199. filePath: filepathss,
  200. showMenu: false,
  201. success: function() {
  202. console.log("打开文档成功");
  203. },
  204. fail: function(err) {
  205. uni.showToast({
  206. title: '暂不支持此类型',
  207. duration: 2000,
  208. icon: "none",
  209. });
  210. }
  211. })
  212. },
  213. fail: function(res) {
  214. uni.hideLoading()
  215. console.log(res); //失败
  216. }
  217. });
  218. // #endif
  219. // #ifdef H5
  220. that.downloadByFileid(that.detaile.brief)
  221. // #endif
  222. },
  223. downloadByFileid(url){
  224. const filePath = url;
  225. const tempLink = document.createElement("a");
  226. tempLink.style.display = "none";
  227. tempLink.href = filePath;
  228. tempLink.setAttribute("download", this.detaile.params.brief);
  229. tempLink.setAttribute("target", "_blank");
  230. document.body.appendChild(tempLink);
  231. tempLink.click();
  232. document.body.removeChild(tempLink);
  233. uni.hideLoading()
  234. },
  235. showShare(){
  236. console.log('点击显示分享')
  237. this.isShowShare = true
  238. this.bottomPositon = 0
  239. this.$forceUpdate()
  240. },
  241. hideShare(){
  242. this.isShowShare = false
  243. this.bottomPositon = '-100%'
  244. },
  245. loadCodeParams(scene) {
  246. let _ts = this;
  247. return new Promise((resolve, reject) => {
  248. let form = {
  249. scene: scene
  250. };
  251. if (!scene) {
  252. resolve();
  253. return false;
  254. }
  255. req.getRequest('/api/code/params', form, data => {
  256. let res = JSON.parse(data.scene)
  257. for(let key in res){
  258. this.options[key] = res[key]
  259. }
  260. resolve(res);
  261. });
  262. });
  263. },
  264. getCardInfo() {
  265. var url = '';
  266. var dataP = {};
  267. url = '/api/v3/visiting/card/user';
  268. dataP.userId = this.options.userId;
  269. req.getRequest(url, dataP, data => {
  270. this.cardInfo = data;
  271. }, false);
  272. },
  273. },
  274. mounted() {
  275. const systemInfo = uni.getSystemInfoSync();
  276. // px转换到rpx的比例
  277. let pxToRpxScale = 750 / systemInfo.windowWidth;
  278. let systems = {
  279. ktxStatusHeight: systemInfo.statusBarHeight * pxToRpxScale, // 状态栏的高度
  280. navigationHeight: 44 * pxToRpxScale // 导航栏的高度
  281. };
  282. systems.barHeight = systems.ktxStatusHeight + systems.navigationHeight;
  283. this.systems = systems;
  284. },
  285. onPageScroll: function(e) {
  286. if (e.scrollTop > this.systems.barHeight) {
  287. this.isTop = 1;
  288. } else {
  289. this.isTop = 0;
  290. }
  291. }
  292. }
  293. </script>
  294. <style>
  295. @import "./index.css";
  296. </style>