commonVue.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  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. {categoryName:'首页',sname:'/index.html',id:1},
  23. {categoryName:'解决方案',sname:'/solution.html',id:2},
  24. {categoryName:'产品服务',sname:'/product.html',id:3},
  25. {categoryName:'新闻动态',sname:'/news.html',id:4},
  26. {categoryName:'关于永天',sname:'/about.html',id:5},
  27. ],
  28. currentPath: '',
  29. articalArray: [], //详情数组
  30. articalArrayRelated: [], //相关新闻
  31. columnTypes: [], //栏目类型
  32. // 公共弹框
  33. centerDialogVisible: false,
  34. dialogDataArray:[],
  35. ruleForm: {
  36. platName: '智慧安防',
  37. consultName: '',
  38. consultPhone: '',
  39. mail: '',
  40. company: '',
  41. consultContent: "",
  42. },
  43. rules: {
  44. platName: [{
  45. required: true,
  46. message: '请选择类型',
  47. trigger: 'change'
  48. },
  49. ],
  50. consultName: [{
  51. required: true,
  52. message: '请输入姓名',
  53. trigger: 'blur'
  54. }, ],
  55. consultPhone: [{
  56. required: true,
  57. message: '请输入正确的电话号码',
  58. pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
  59. trigger: 'change'
  60. }],
  61. mail: [{
  62. required: false,
  63. type: "email",
  64. message: "请输入正确的邮箱地址",
  65. trigger: 'blur'
  66. }],
  67. },
  68. //首页
  69. homeList: [],
  70. status: false,
  71. // 新闻
  72. news: [],
  73. goPage: 1,
  74. totalPageNum: 1,
  75. totalPageSzie: 1,
  76. loading: true,
  77. categoryid:0,
  78. requestParams:{
  79. categoryid: this.id,
  80. pageNum: 1,
  81. pageSize: 9,
  82. title: ''
  83. },
  84. //解决方案旧
  85. array: [],
  86. //新闻详情旧
  87. articleInfo: {},
  88. previousInfo: {},
  89. nextInfo: {},
  90. relativeArr: [],
  91. // ariticle_id: 0,
  92. },
  93. computed: {
  94. // 新闻详情旧
  95. isNews: function () {
  96. return (this.articleInfo.type == 1);
  97. },
  98. hasPrevious: function () {
  99. return Object.keys(this.previousInfo).length > 0;
  100. },
  101. hasNext: function () {
  102. return Object.keys(this.nextInfo).length > 0;
  103. }
  104. },
  105. created: function () {
  106. this.requestParams.categoryid = this.getQuery('id') ? this.getQuery('id') : ''
  107. // this.ariticle_id = this.getQuery('id')
  108. this.requestParams.title = this.getQuery('title') ? this.getQuery('title') : ''
  109. },
  110. mounted: function () {
  111. _this = this
  112. this.getColumnData()
  113. },
  114. methods: {
  115. //获取栏目
  116. getColumnData() {
  117. this.columnTypes = []
  118. $.ajax({
  119. type: 'get',
  120. dataType: 'json',
  121. url: window.FQDN2 + 'siteCategory/siteCategoryList',
  122. }).done(function (res) {
  123. _this.columnList = res.data;
  124. _this.currentPath = window.location.pathname
  125. for (let i = 0; i < res.data.length; i++) {
  126. // console.log(res.data[i].sname)
  127. // console.log(window.location.pathname)
  128. if (res.data[i].categoryName == '首页' && window.location.pathname == '/index.html') {
  129. //首页旧
  130. jQuery.ajax({
  131. type: 'POST',
  132. dataType: 'json',
  133. url: window.FQDN + 'Index/index',
  134. }).done(function (res) {
  135. _this.homeList = res
  136. _this.status = true
  137. }).fail(function (err) {});
  138. }
  139. if (res.data[i].categoryName == '产品服务' && window.location.pathname == '/product/read.html') {
  140. _this.currentPath = '/product/index.html' //产品详情时栏目高亮
  141. }
  142. if (res.data[i].categoryName == '解决方案' && window.location.pathname == '/solution/read.html') {
  143. _this.currentPath = '/solution/index.html' //产品详情时栏目高亮
  144. }
  145. if (res.data[i].categoryName == '解决方案') {
  146. _this.dialogDataArray=(res.data[i].children)
  147. _this.ruleForm.platName= _this.dialogDataArray[0].categoryName
  148. }
  149. if (res.data[i].categoryName == '新闻动态' && window.location.pathname == '/news/read.html') {
  150. _this.currentPath = '/news/index.html' //新闻详情时栏目高亮
  151. //获取相关新闻数据
  152. setTimeout(()=>{
  153. _this.requestParams.title=''
  154. _this.getArticalData( _this.requestParams,1)
  155. },1)
  156. //新闻详情旧
  157. jQuery.ajax({
  158. type: 'POST',
  159. dataType: 'json',
  160. url: window.FQDN + 'agw/journalism_details',
  161. data: {
  162. id: 154
  163. }
  164. }).done(function (res) {
  165. if (!res.msg) {
  166. return;
  167. }
  168. _this.loading = false;
  169. _this.articleInfo = res;
  170. _this.relativeArr = res.related;
  171. console.log(_this.relativeArr)
  172. if (res.previous != null) {
  173. _this.previousInfo = res.previous;
  174. }
  175. if (res.next != null) {
  176. _this.nextInfo = res.next;
  177. }
  178. }).fail(function (err) {});
  179. }
  180. if (res.data[i].categoryName == '关于永天' && window.location.pathname.indexOf('about') > -1) {
  181. _this.columnTypes = res.data[i].children
  182. _this.requestParams.categoryid=_this.getQuery('id')
  183. console.log(_this.requestParams)
  184. _this.getArticalData(_this.requestParams)
  185. //关于永天旧
  186. $.ajax({
  187. type: 'POST',
  188. dataType: 'json',
  189. url: window.FQDN + 'Aboutus/index',
  190. }).done(function (arr) {
  191. // console.log(arr)
  192. _this.array = arr;
  193. }).fail(function (err) {});
  194. }
  195. if (res.data[i].children.length > 0) {
  196. if (res.data[i].categoryName == '解决方案' && window.location.pathname.indexOf('solution') > -1) {
  197. _this.columnTypes = res.data[i].children
  198. _this.requestParams.categoryid = (_this.getQuery('isUrlId') == 1) ? _this.getQuery('id') : _this.columnTypes[0].id;
  199. _this.getArticalData(_this.requestParams)
  200. //解决方案旧
  201. $.ajax({
  202. type: 'POST',
  203. dataType: 'json',
  204. url: window.FQDN + 'Solution/index',
  205. data: {
  206. id: '1'
  207. }
  208. }).done(function (arr) {
  209. _this.array = arr;
  210. console.log(_this.array)
  211. }).fail(function (err) {});
  212. }
  213. if (res.data[i].categoryName == '新闻动态' && window.location.pathname.indexOf('news') > -1) {
  214. _this.columnTypes = res.data[i].children
  215. _this.requestParams.categoryid = (_this.getQuery('isUrlId') == 1) ? _this.getQuery('id') : _this.columnTypes[0].id;
  216. _this.getArticalData(_this.requestParams)
  217. }
  218. if (res.data[i].categoryName == '产品服务' && window.location.pathname.indexOf('product') > -1) {
  219. _this.columnTypes = res.data[i].children
  220. _this.requestParams.categoryid = (_this.getQuery('isUrlId') == 1) ? _this.getQuery('id') : _this.columnTypes[0].id;
  221. _this.getArticalData(_this.requestParams)
  222. }
  223. }
  224. }
  225. })
  226. },
  227. //获取内容
  228. getArticalData(requestParams,type) {
  229. $.ajax({
  230. type: 'GET',
  231. dataType: 'json',
  232. url: window.FQDN2 + 'siteArticle/siteArticleList',
  233. data: requestParams
  234. }).done(function (res) {
  235. var aa
  236. var bb
  237. if(type==1){
  238. bb=res.data.records
  239. }else{
  240. aa= res.data.records;
  241. // aa.sort(_this.compare("lmtitle"))
  242. _this.articalArray = aa;
  243. }
  244. if(bb){
  245. _this.articalArrayRelated =bb.filter(obj => obj.id != _this.articalArray[0].id);
  246. console.log(_this.articalArrayRelated)
  247. }
  248. _this.loading = false;
  249. _this.totalPageSzie = res.data.total
  250. _this.totalPageNum = Math.ceil(res.data.total / res.data.size);
  251. }).fail(function (err) {});
  252. },
  253. //类型点击
  254. facilityClick(e, item) {
  255. this.requestParams.categoryid = item.id
  256. this.requestParams.pageNum = 1
  257. this.getArticalData(this.requestParams)
  258. },
  259. // 分页
  260. oneInnerBox: function (param) {
  261. window.location = "./read.html?id=" + param.categoryid + "&title=" + param.title+ "&isUrlId=1";
  262. // window.location = "./read.html?id=154"
  263. },
  264. enterPage: function (res) {
  265. if (this.goPage >= 1 && this.goPage <= this.totalPageNum) {
  266. this.requestParams.pageNum = this.goPage
  267. this.getArticalData(this.requestParams)
  268. } else {
  269. this.goPage = 1
  270. alert('输入页数有误!')
  271. }
  272. },
  273. currentChange: function (res) {
  274. this.requestParams.pageNum = res
  275. this.getArticalData(this.requestParams)
  276. },
  277. //首页
  278. scrollToTop() {
  279. window.scrollTo({
  280. top: 0,
  281. behavior: "smooth"
  282. });
  283. },
  284. //公共弹框
  285. submitForm(formName) {
  286. _this = this
  287. this.$refs[formName].validate((valid) => {
  288. if (valid) {
  289. console.log(_this.ruleForm)
  290. let param = JSON.stringify(_this.ruleForm)
  291. jQuery.ajax({
  292. type: 'POST',
  293. // dataType: 'json',
  294. contentType: 'application/json;charset=UTF-8',
  295. url: window.FQDN2 + 'siteReview',
  296. data: param
  297. }).done(function (res) {
  298. if (res.status === "SUCCESS") {
  299. _this.$message({
  300. message: '提交成功',
  301. type: 'success'
  302. });
  303. _this.centerDialogVisible = false
  304. _this.$refs[formName].resetFields(); //重置from校验
  305. }
  306. }).fail(function (err) {});
  307. } else {
  308. console.log('error submit!!');
  309. return false;
  310. }
  311. });
  312. },
  313. resetForm(formName) {
  314. this.$refs[formName].resetFields();
  315. this.centerDialogVisible = false
  316. },
  317. // 排序
  318. compare(property) {
  319. return function (a, b) {
  320. var value1 = a[property];
  321. var value2 = b[property];
  322. return value1 - value2;
  323. }
  324. },
  325. // 获取路由参数
  326. getQuery(name) {
  327. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  328. var r = window.location.search.substr(1).match(reg);
  329. if (r != null) return decodeURI(r[2]);
  330. return null;
  331. },
  332. //获得年月日时分秒 //传入日期//例:2020-10-27T14:36:23
  333. timeFormatSeconds(time) {
  334. var d = time ? new Date(time) : new Date();
  335. var year = d.getFullYear();
  336. var month = d.getMonth() + 1;
  337. var day = d.getDate();
  338. var hours = d.getHours();
  339. var min = d.getMinutes();
  340. var seconds = d.getSeconds();
  341. if (month < 10) month = '0' + month;
  342. if (day < 10) day = '0' + day;
  343. if (hours < 0) hours = '0' + hours;
  344. if (min < 10) min = '0' + min;
  345. if (seconds < 10) seconds = '0' + seconds;
  346. return (year + '-' + month + '-' + day + ' ' + hours + ':' + min + ':' + seconds);
  347. }
  348. }
  349. });