wxnews2.html 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>洪楼Plus-让买房更省心</title>
  5. <meta charset="utf-8">
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7. <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
  8. <meta content="telephone=no, address=no" name="format-detection" />
  9. <style>
  10. html,body,div,span,iframe,h1,h2,h3,h4,h5,h6,p,pre,a,address,img,small,strong,sub,sup,tt,b,i,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section,canvas,audio,video {
  11. margin: 0;
  12. padding: 0;
  13. border: 0;
  14. font-size: 100%;
  15. -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  16. vertical-align: baseline
  17. }
  18. article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section {
  19. display: block
  20. }
  21. ol,
  22. ul {
  23. list-style: none
  24. }
  25. table {
  26. border-collapse: collapse;
  27. border-spacing: 0
  28. }
  29. button,
  30. img,
  31. fieldset {
  32. display: block;
  33. border: 0
  34. }
  35. button,
  36. html input[type=button],
  37. input[type=reset],
  38. input[type=submit] {
  39. -webkit-appearance: button;
  40. cursor: pointer;
  41. padding: 0
  42. }
  43. input[type=checkbox],
  44. input[type=radio] {
  45. cursor: pointer;
  46. padding: 0
  47. }
  48. a {
  49. color: #4183c4;
  50. text-decoration: none
  51. }
  52. a:hover {
  53. text-decoration: none
  54. }
  55. html {
  56. -ms-text-size-adjust: 100%;
  57. -webkit-text-size-adjust: 100%
  58. }
  59. body {
  60. font-family: "Microsoft YaHei", "Segoe UI", "Lucida Grande", Helvetica, Arial, FreeSans, Arimo, "Droid Sans", "wenquanyi micro hei", "Hiragino Sans GB", "Hiragino Sans GB W3", FontAwesome, sans-serif;
  61. font-weight: 400;
  62. line-height: 1.42;
  63. min-width: 320px;
  64. max-width: 640px;
  65. margin: 0 auto;
  66. color: #333;
  67. font-size: 16px;
  68. background: #fff;
  69. -webkit-font-smoothing: antialiased;
  70. -moz-osx-font-smoothing: grayscale
  71. }
  72. /*主体css*/
  73. .app-view{
  74. padding: 0 16px 20px;
  75. }
  76. .app-view img{
  77. max-width: 100%;
  78. }
  79. .app-view .title{
  80. margin: 20px 0;
  81. font-size: 24px;
  82. }
  83. .app-view .other-info{
  84. margin-bottom: 10px;
  85. color: #b2b2b2;
  86. }
  87. #content, #content *, #content div, #content p, #content span {
  88. word-break: break-all!important;
  89. }
  90. </style>
  91. <script type="text/javascript" src="https://res2.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
  92. </head>
  93. <body>
  94. <div id="app">
  95. <div class="app-view">
  96. <h3 class="title" id="title"></h3>
  97. <p class="other-info">
  98. <span style="color:#576b95;padding-right:10px;font-weight: bold;" Id="from"></span>
  99. <span id="time"></span>
  100. <wx-open-launch-weapp
  101. id="launch-btn"
  102. username="gh_998dfd1fc347"
  103. path="pages/index/index.html"
  104. >
  105. <span style="color:#576b95;padding-left:10px;font-weight: bold;">去小程序了解更多南昌楼市信息>></span>
  106. </wx-open-launch-weapp>
  107. <wx-open-launch-weapp
  108. id="launch-btn2"
  109. username="gh_998dfd1fc347"
  110. path="pages/index/index.html"
  111. >
  112. <script type="text/wxtag-template">
  113. <style>.btn { padding: 12px }</style>
  114. <button class="btn">打开小程序</button>
  115. </script>
  116. </wx-open-launch-weapp>
  117. </p>
  118. <div id="content"></div>
  119. </div>
  120. </div>
  121. </body>
  122. </html>
  123. <script>
  124. // 封装ajax
  125. function ajax(list) {
  126. if (XMLHttpRequest) {
  127. var req = new XMLHttpRequest();
  128. } else {
  129. var req = new ActiveXObject("Microsoft.XMLHTTP");
  130. }
  131. var type = list.type || 'get';
  132. var data = list.data || '';
  133. var isAysnch = list.isAysnch || true;
  134. if (type == 'get') {
  135. req.open(type, list.url + "?" + data, isAysnch);
  136. req.send(null);
  137. } else {
  138. // console.log(req)
  139. // req.responseType = 'json'
  140. req.open(type, list.url, isAysnch);
  141. req.send(data);
  142. }
  143. req.onload = function () {
  144. var d = req.responseText;
  145. list.success(d);
  146. }
  147. }
  148. //获取路由参数
  149. function getRouteQuery () {
  150. var searchStr = window.location.search.slice(1)
  151. var searchArr = searchStr.split('&')
  152. var query = {}
  153. for (var i = 0; i < searchArr.length; i++) {
  154. var item = searchArr[i].split('=')
  155. query[item[0]] = item[1]
  156. }
  157. return query
  158. }
  159. //请求数据
  160. var novelId = getRouteQuery().id
  161. if (novelId) {
  162. var formData = new FormData();
  163. formData.append("id", novelId);
  164. ajax({
  165. type:'post',
  166. url:'https://api.honglouplus.com/api/h5/information',
  167. data: formData,
  168. success:function(msg){
  169. var res = JSON.parse(msg)
  170. var newsInfo = res.data
  171. var content = newsInfo.content
  172. document.getElementById('content').innerHTML = content
  173. var timeArr = newsInfo.create_at.split(' ')
  174. var time = timeArr[0]
  175. document.getElementById('title').innerHTML = newsInfo.title
  176. document.getElementById('time').innerHTML = time
  177. document.getElementById('from').innerHTML = newsInfo.author
  178. value = content.replace(/(\n)/g, "");
  179. value = value.replace(/(\t)/g, "");
  180. value = value.replace(/(\r)/g, "");
  181. value = value.replace(/<\/?[^>]*>/g, "");
  182. value = value.replace(/\s*/g, "");
  183. value = value.replace(/&nbsp;/ig, "");
  184. var desc = value.substring(0, 40);
  185. // console.log(desc)
  186. configJsSDKAndDoSomething(res.jssdk, newsInfo.title, newsInfo.pri_image, desc)
  187. }
  188. })
  189. } else {
  190. window.alert('缺少文章ID')
  191. }
  192. var shareImgUrl = 'http://icon.honglounews.com/plus.png';
  193. function configJsSDKAndDoSomething(config, title, imgUrl, desc){
  194. wx.config({
  195. debug: true,
  196. appId: config.appId,
  197. timestamp: config.timestamp,
  198. nonceStr: config.nonceStr,
  199. signature: config.signature,
  200. jsApiList: config.jsApiList,
  201. openTagList: ['wx-open-launch-weapp'],
  202. })
  203. wx.error(function(error){
  204. console.log(error);
  205. });
  206. wx.ready(function () {
  207. wx.updateAppMessageShareData({
  208. title: title,
  209. desc: desc,
  210. link: location.href,
  211. imgUrl: imgUrl,
  212. success: function () {
  213. alert(title);
  214. }
  215. });
  216. wx.updateTimelineShareData({
  217. title: title,
  218. link: location.href,
  219. imgUrl: imgUrl,
  220. success: function () {
  221. alert(desc);
  222. }
  223. });
  224. var btn = document.getElementById('launch-btn');
  225. btn.addEventListener('launch', function (e) {
  226. alert('success');
  227. });
  228. btn.addEventListener('error', function (e) {
  229. alert('fail', e.detail);
  230. });
  231. var btn = document.getElementById('launch-btn2');
  232. btn.addEventListener('launch', function (e) {
  233. alert('success2success2');
  234. });
  235. btn.addEventListener('error', function (e) {
  236. alert('fail2', e.detail);
  237. });
  238. });
  239. }
  240. </script>