commonVue.js 12 KB

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