commonVue.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  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. setTimeout(()=>{
  142. _this.requestParams.title=''
  143. _this.getArticalData( _this.requestParams,1)
  144. },1)
  145. }
  146. if (res.data[i].categoryName == '解决方案' && window.location.pathname == '/solution/read.html') {
  147. _this.currentPath = '/solution/index.html' //产品详情时栏目高亮
  148. //获取相关新闻数据
  149. setTimeout(()=>{
  150. _this.requestParams.title=''
  151. _this.getArticalData( _this.requestParams,1)
  152. },1)
  153. }
  154. if (res.data[i].categoryName == '解决方案') {
  155. _this.dialogDataArray=(res.data[i].children)
  156. _this.ruleForm.platName= _this.dialogDataArray[0].categoryName
  157. }
  158. if (res.data[i].categoryName == '新闻动态' && window.location.pathname == '/news/read.html') {
  159. _this.currentPath = '/news/index.html' //新闻详情时栏目高亮
  160. //获取相关新闻数据
  161. setTimeout(()=>{
  162. _this.requestParams.title=''
  163. _this.getArticalData( _this.requestParams,1)
  164. },1)
  165. //新闻详情旧
  166. jQuery.ajax({
  167. type: 'POST',
  168. dataType: 'json',
  169. url: window.FQDN + 'agw/journalism_details',
  170. data: {
  171. id: 154
  172. }
  173. }).done(function (res) {
  174. if (!res.msg) {
  175. return;
  176. }
  177. _this.loading = false;
  178. _this.articleInfo = res;
  179. _this.relativeArr = res.related;
  180. console.log(_this.relativeArr)
  181. if (res.previous != null) {
  182. _this.previousInfo = res.previous;
  183. }
  184. if (res.next != null) {
  185. _this.nextInfo = res.next;
  186. }
  187. }).fail(function (err) {});
  188. }
  189. if (res.data[i].categoryName == '关于永天' && window.location.pathname.indexOf('about') > -1) {
  190. _this.columnTypes = res.data[i].children
  191. _this.requestParams.categoryid=_this.getQuery('id')
  192. console.log(_this.requestParams)
  193. _this.getArticalData(_this.requestParams)
  194. //关于永天旧
  195. $.ajax({
  196. type: 'POST',
  197. dataType: 'json',
  198. url: window.FQDN + 'Aboutus/index',
  199. }).done(function (arr) {
  200. // console.log(arr)
  201. _this.array = arr;
  202. }).fail(function (err) {});
  203. }
  204. if (res.data[i].children.length > 0) {
  205. if (res.data[i].categoryName == '解决方案' && window.location.pathname.indexOf('solution') > -1) {
  206. _this.columnTypes = res.data[i].children
  207. _this.requestParams.categoryid = (_this.getQuery('isUrlId') == 1) ? _this.getQuery('id') : _this.columnTypes[0].id;
  208. _this.getArticalData(_this.requestParams)
  209. //解决方案旧
  210. $.ajax({
  211. type: 'POST',
  212. dataType: 'json',
  213. url: window.FQDN + 'Solution/index',
  214. data: {
  215. id: '1'
  216. }
  217. }).done(function (arr) {
  218. _this.array = arr;
  219. console.log(_this.array)
  220. }).fail(function (err) {});
  221. }
  222. if (res.data[i].categoryName == '新闻动态' && window.location.pathname.indexOf('news') > -1) {
  223. _this.columnTypes = res.data[i].children
  224. _this.requestParams.categoryid = (_this.getQuery('isUrlId') == 1) ? _this.getQuery('id') : _this.columnTypes[0].id;
  225. _this.getArticalData(_this.requestParams)
  226. }
  227. if (res.data[i].categoryName == '产品服务' && window.location.pathname.indexOf('product') > -1) {
  228. _this.columnTypes = res.data[i].children
  229. _this.requestParams.categoryid = (_this.getQuery('isUrlId') == 1) ? _this.getQuery('id') : _this.columnTypes[0].id;
  230. _this.getArticalData(_this.requestParams)
  231. }
  232. }
  233. }
  234. })
  235. },
  236. //获取内容
  237. getArticalData(requestParams,type) {
  238. $.ajax({
  239. type: 'GET',
  240. dataType: 'json',
  241. url: window.FQDN2 + 'siteArticle/siteArticleList',
  242. data: requestParams
  243. }).done(function (res) {
  244. var aa
  245. var bb
  246. if(type==1){
  247. bb=res.data.records
  248. }else{
  249. aa= res.data.records;
  250. // aa.sort(_this.compare("lmtitle"))
  251. _this.articalArray = aa;
  252. }
  253. if(bb){
  254. _this.articalArrayRelated =bb.filter(obj => obj.id != _this.articalArray[0].id);
  255. console.log(_this.articalArrayRelated)
  256. }
  257. _this.loading = false;
  258. _this.totalPageSzie = res.data.total
  259. _this.totalPageNum = Math.ceil(res.data.total / res.data.size);
  260. }).fail(function (err) {});
  261. },
  262. //类型点击
  263. facilityClick(e, item) {
  264. this.requestParams.categoryid = item.id
  265. this.requestParams.pageNum = 1
  266. this.getArticalData(this.requestParams)
  267. },
  268. // 分页
  269. oneInnerBox: function (param) {
  270. window.location = "./read.html?id=" + param.categoryid + "&title=" + param.title+ "&isUrlId=1";
  271. // window.location = "./read.html?id=154"
  272. },
  273. enterPage: function (res) {
  274. if (this.goPage >= 1 && this.goPage <= this.totalPageNum) {
  275. this.requestParams.pageNum = this.goPage
  276. this.getArticalData(this.requestParams)
  277. } else {
  278. this.goPage = 1
  279. alert('输入页数有误!')
  280. }
  281. },
  282. currentChange: function (res) {
  283. this.requestParams.pageNum = res
  284. this.getArticalData(this.requestParams)
  285. },
  286. //首页
  287. scrollToTop() {
  288. window.scrollTo({
  289. top: 0,
  290. behavior: "smooth"
  291. });
  292. },
  293. //公共弹框
  294. submitForm(formName) {
  295. _this = this
  296. this.$refs[formName].validate((valid) => {
  297. if (valid) {
  298. console.log(_this.ruleForm)
  299. let param = JSON.stringify(_this.ruleForm)
  300. jQuery.ajax({
  301. type: 'POST',
  302. // dataType: 'json',
  303. contentType: 'application/json;charset=UTF-8',
  304. url: window.FQDN2 + 'siteReview',
  305. data: param
  306. }).done(function (res) {
  307. if (res.status === "SUCCESS") {
  308. _this.$message({
  309. message: '提交成功',
  310. type: 'success'
  311. });
  312. _this.centerDialogVisible = false
  313. _this.$refs[formName].resetFields(); //重置from校验
  314. }
  315. }).fail(function (err) {});
  316. } else {
  317. console.log('error submit!!');
  318. return false;
  319. }
  320. });
  321. },
  322. resetForm(formName) {
  323. this.$refs[formName].resetFields();
  324. this.centerDialogVisible = false
  325. },
  326. // 排序
  327. compare(property) {
  328. return function (a, b) {
  329. var value1 = a[property];
  330. var value2 = b[property];
  331. return value1 - value2;
  332. }
  333. },
  334. // 获取路由参数
  335. getQuery(name) {
  336. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  337. var r = window.location.search.substr(1).match(reg);
  338. if (r != null) return decodeURI(r[2]);
  339. return null;
  340. },
  341. //获得年月日时分秒 //传入日期//例:2020-10-27T14:36:23
  342. timeFormatSeconds(time) {
  343. var d = time ? new Date(time) : new Date();
  344. var year = d.getFullYear();
  345. var month = d.getMonth() + 1;
  346. var day = d.getDate();
  347. var hours = d.getHours();
  348. var min = d.getMinutes();
  349. var seconds = d.getSeconds();
  350. if (month < 10) month = '0' + month;
  351. if (day < 10) day = '0' + day;
  352. if (hours < 0) hours = '0' + hours;
  353. if (min < 10) min = '0' + min;
  354. if (seconds < 10) seconds = '0' + seconds;
  355. return (year + '-' + month + '-' + day + ' ' + hours + ':' + min + ':' + seconds);
  356. }
  357. }
  358. });