commonVue.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. // 定义一个名为 button-counter 的新组件
  2. Vue.component('button-counter', {
  3. props: ['title'],
  4. data () {
  5. return {
  6. count: 0
  7. }
  8. },
  9. methods: {
  10. addCount() {
  11. this.count++
  12. }
  13. },
  14. template: '<button @click="addCount">{{ title }} : You clicked me {{ count }} times.</button>'
  15. })
  16. var app = new Vue({
  17. el: '#app',
  18. data: {
  19. //公共
  20. id: null,
  21. columnList:[],
  22. currentPath:'',
  23. articalArray: [], //详情数组
  24. columnTypes: [], //栏目类型
  25. //首页
  26. homeList: [],
  27. status: false,
  28. //解决方案旧
  29. array: [],
  30. // 新聞
  31. news: [],
  32. goPage: 1,
  33. one_page_size: 3,
  34. currentPageNum: 1,
  35. totalPageNum: 1,
  36. totalPageSzie: 4,
  37. loading: true,
  38. //新闻详情旧
  39. articleInfo: {},
  40. previousInfo: {},
  41. nextInfo: {},
  42. relativeArr: [],
  43. ariticle_id: 0,
  44. // 产品服务旧
  45. viweState: false,
  46. getProductType: [],
  47. getProductList: [],
  48. details: {},
  49. tabs: 0,
  50. tabsId: '',
  51. banner: undefined,
  52. item: undefined
  53. },
  54. computed: {
  55. // 新闻详情旧
  56. isNews: function() {
  57. return (this.articleInfo.type == 1);
  58. },
  59. hasPrevious: function() {
  60. return Object.keys(this.previousInfo).length > 0;
  61. },
  62. hasNext: function() {
  63. return Object.keys(this.nextInfo).length > 0;
  64. }
  65. },
  66. created: function () {
  67. this.ariticle_id = this.getQuery('id')
  68. // this.title = this.getQuery('title')?this.getQuery('title'):''
  69. this.title = this.getQuery('title')?this.getQuery('title'):''
  70. },
  71. mounted: function () {
  72. _this = this
  73. this.getColumnData()
  74. this.getProductTypeAjax()
  75. if (JSON.stringify(JSON.parse(localStorage.getItem("item")).children) != "[]") {
  76. this.banner = JSON.parse(localStorage.getItem("item")).imagePath
  77. console.log('this.banner')
  78. console.log(this.banner)
  79. if (window.location.search) {
  80. if (window.location.search.indexOf("detailId") > -1) {
  81. this.detailsData(this.getString('detailId')[2])
  82. }
  83. if (window.location.search.indexOf("id") > -1) {
  84. this.getList(this.getString('id')[2])
  85. }
  86. } else {
  87. this.getList()
  88. }
  89. }
  90. },
  91. methods: {
  92. //获取栏目
  93. getColumnData() {
  94. $.ajax({
  95. type: 'get',
  96. dataType: 'json',
  97. url: window.FQDN2 + 'siteCategory/siteCategoryList',
  98. }).done(function (res) {
  99. _this.columnList=res.data;
  100. _this.currentPath=window.location.pathname
  101. for (let i = 0; i < res.data.length; i++) {
  102. // console.log(res.data[i].sname)
  103. // console.log(window.location.pathname)
  104. if (res.data[i].categoryName == '首页'&& window.location.pathname=='/index.html') {
  105. //首页旧
  106. jQuery.ajax({
  107. type: 'POST',
  108. dataType: 'json',
  109. url: window.FQDN + 'Index/index',
  110. }).done(function (res) {
  111. _this.homeList = res
  112. _this.status = true
  113. }).fail(function (err) {});
  114. }
  115. if (res.data[i].categoryName == '新闻动态'&& window.location.pathname=='/news/read.html') {
  116. _this.currentPath='/news/index.html' //新闻详情时栏目高亮
  117. console.log(res.data[i].categoryName)
  118. //新闻详情旧
  119. jQuery.ajax({
  120. type: 'POST',
  121. dataType: 'json',
  122. url: window.FQDN + 'agw/journalism_details',
  123. data: {
  124. id: 154
  125. }
  126. }).done(function(res) {
  127. if (!res.msg) {
  128. return;
  129. }
  130. _this.loading = false;
  131. _this.articleInfo = res;
  132. _this.relativeArr = res.related;
  133. console.log(_this.relativeArr)
  134. if (res.previous != null) {
  135. _this.previousInfo = res.previous;
  136. }
  137. if (res.next != null) {
  138. _this.nextInfo = res.next;
  139. }
  140. }).fail(function(err) {});
  141. }
  142. if (res.data[i].categoryName == '关于永天'&& window.location.pathname.indexOf('about')>-1) {
  143. //关于永天旧
  144. $.ajax({
  145. type: 'POST',
  146. dataType: 'json',
  147. url: window.FQDN + 'Aboutus/index',
  148. }).done(function(arr) {
  149. // console.log(arr)
  150. _this.array = arr;
  151. }).fail(function(err) {});
  152. }
  153. if (res.data[i].children.length > 0) {
  154. if (res.data[i].categoryName == '解决方案'&& window.location.pathname.indexOf('solution')>-1) {
  155. _this.columnTypes = res.data[i].children
  156. _this.id = _this.getQuery('id') ? _this.getQuery('id') : _this.columnTypes[0].id;
  157. _this.getArticalData(_this.id ? _this.id : _this.columnTypes[0].id)
  158. //解决方案旧
  159. $.ajax({
  160. type: 'POST',
  161. dataType: 'json',
  162. url: window.FQDN + 'Solution/index',
  163. data: {
  164. id: '1'
  165. }
  166. }).done(function (arr) {
  167. _this.array = arr;
  168. console.log(_this.array)
  169. }).fail(function (err) {});
  170. }
  171. if (res.data[i].categoryName == '新闻动态'&& window.location.pathname.indexOf('news')>-1) {
  172. _this.columnTypes = res.data[i].children
  173. _this.id = _this.getQuery('id') ? _this.getQuery('id') : _this.columnTypes[0].id;
  174. _this.getArticalData(_this.id ? _this.id : _this.columnTypes[0].id)
  175. }
  176. }
  177. }
  178. })
  179. },
  180. //获取内容
  181. getArticalData(param) {
  182. $.ajax({
  183. type: 'GET',
  184. dataType: 'json',
  185. url: window.FQDN2 + 'siteArticle/siteArticleList',
  186. data: {
  187. categoryid: param,
  188. pageNum:_this.currentPageNum,
  189. pageSize:_this.one_page_size,
  190. title:_this.title
  191. }
  192. }).done(function (res) {
  193. var aa = res.data.records;
  194. aa.sort(_this.compare("lmtitle"))
  195. _this.loading = false;
  196. _this.articalArray = aa;
  197. _this.totalPageSzie = res.data.total
  198. _this.totalPageNum = Math.ceil(res.data.total / res.data.size);
  199. console.log(aa)
  200. }).fail(function (err) {});
  201. },
  202. //类型点击
  203. facilityClick(e, item) {
  204. this.id = item.id
  205. this.getArticalData(item.id)
  206. this.currentPageNum=1
  207. // console.log(item.id)
  208. },
  209. // 产品服务旧
  210. getString(key) {
  211. // 获取地址栏的参数
  212. var url = window.location.search;
  213. //正则表达式筛选
  214. var reg = new RegExp("(^|&)" + key + "=([^&]*)(&|$)");
  215. //匹配参数
  216. var result = url.substr(1).match(reg);
  217. return result
  218. },
  219. /** 获取分类 */
  220. getList(id) {
  221. let _this = this
  222. _this.tabs = id
  223. _this.tabsId = id
  224. let path = JSON.parse(localStorage.getItem("item")).sname
  225. let data = JSON.parse(localStorage.getItem("item")).children
  226. for (let i = 0; i < data.length; i++) {
  227. if (id == data[i].id) {
  228. var li = $(`
  229. <a class="active" href=?id=${data[i].id}>
  230. ${data[i].categoryName}
  231. </a>
  232. `)
  233. $('.tabs_selected a').siblings().removeClass('active')
  234. $('#' + id).addClass('active')
  235. } else {
  236. var li = $(`
  237. <a href=?id=${data[i].id}>${data[i].categoryName}</a>
  238. `)
  239. }
  240. // $(".grid-filter>ul").append(li)
  241. }
  242. if (!id) {
  243. let li = $(`<a class="active" href="index.html">全部</a>`)
  244. $(".grid-filter>ul").prepend(li)
  245. _this.getListData(_this.tabsId, 1, _this.one_page_size)
  246. } else {
  247. let li = $(`<a href="index.html">全部</a>`)
  248. _this.getListData(id, 1, _this.one_page_size)
  249. $(".grid-filter>ul").prepend(li)
  250. }
  251. },
  252. /** 获取分类下数据 */
  253. getListData(id = undefined, page, size) {
  254. let _this = this
  255. jQuery.ajax({
  256. type: 'get',
  257. dataType: 'json',
  258. url: window.FQDN2 + 'siteArticle/siteArticleList',
  259. data: {
  260. categoryid: id,
  261. pageNum: page,
  262. pageSize: size,
  263. }
  264. }).done(function(res) {
  265. _this.getProductList = res.data.records
  266. _this.totalPageNum = Math.ceil((res.data.total / res.data.size))
  267. _this.totalPageSzie = res.data.total
  268. _this.currentPageNum = res.data.current
  269. if (res.data.records.length > 0) {
  270. _this.loading = false
  271. } else {
  272. _this.loading = true
  273. }
  274. }).fail(function(err) {});
  275. },
  276. /** 获取数据详情 */
  277. productDetails(data) {
  278. if (data) {
  279. localStorage.setItem("productDetail", JSON.stringify(data))
  280. window.location = `?detailId=${data.id}`
  281. } else {
  282. window.history.go(-1)
  283. setTimeout(() => {
  284. localStorage.removeItem("productDetail")
  285. }, 1000)
  286. }
  287. },
  288. detailsData(id) {
  289. let data = JSON.parse(localStorage.getItem("productDetail"))
  290. if (data.id == id) {
  291. this.details = data
  292. this.viweState = true
  293. }
  294. },
  295. CloseDetail(){
  296. this.viweState=false;
  297. window.history.replace(-1)
  298. location.replace(location.href);
  299. },
  300. getProductTypeAjax() {
  301. var _this = this;
  302. jQuery.ajax({
  303. type: 'POST',
  304. dataType: 'json',
  305. url: window.FQDN2 + 'Product/getProductType',
  306. }).done(function(res) {
  307. _this.getProductType = res
  308. }).fail(function(err) {});
  309. },
  310. //end
  311. // 分页
  312. oneInnerBox: function(param) {
  313. window.location = "./read.html?id=" + param.categoryid+'&title='+param.title;
  314. // window.location = "./read.html?id=154"
  315. },
  316. enterPage: function(res) {
  317. if (this.goPage >= 1 && this.goPage <= this.totalPageNum) {
  318. this.currentPageNum = this.goPage
  319. this.getArticalData(this.id ? this.id : this.columnTypes[0].id)
  320. } else {
  321. this.goPage = 1
  322. alert('输入页数有误!')
  323. }
  324. },
  325. currentChange: function(res) {
  326. this.currentPageNum = res
  327. this.getArticalData(this.id ? this.id : this.columnTypes[0].id)
  328. },
  329. // 排序
  330. compare(property) {
  331. return function (a, b) {
  332. var value1 = a[property];
  333. var value2 = b[property];
  334. return value1 - value2;
  335. }
  336. },
  337. // 获取路由参数
  338. getQuery(name) {
  339. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  340. var r = window.location.search.substr(1).match(reg);
  341. if (r != null) return decodeURI(r[2]); return null;
  342. },
  343. //获得年月日时分秒
  344. //传入日期//例:2020-10-27T14:36:23
  345. timeFormatSeconds(time) {
  346. var d = time ? new Date(time) : new Date();
  347. var year = d.getFullYear();
  348. var month = d.getMonth() + 1;
  349. var day = d.getDate();
  350. var hours = d.getHours();
  351. var min = d.getMinutes();
  352. var seconds = d.getSeconds();
  353. if (month < 10) month = '0' + month;
  354. if (day < 10) day = '0' + day;
  355. if (hours < 0) hours = '0' + hours;
  356. if (min < 10) min = '0' + min;
  357. if (seconds < 10) seconds = '0' + seconds;
  358. return (year + '-' + month + '-' + day + ' ' + hours + ':' + min + ':' + seconds);
  359. }
  360. }
  361. });