HomeIndex.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. <!--
  2. * @Description: 首页
  3. * @Author: 空白格
  4. * @Date: 2022-08-10 11:26:40
  5. * @LastEditors: 空白格
  6. * @LastEditTime: 2022-12-15 10:18:02
  7. * @FilePath: \veterans_client_web\src\views\Home\HomeIndex.vue
  8. * @Copyright: Copyright (c) 2016~2022 by 空白格, All Rights Reserved.
  9. -->
  10. <template>
  11. <div class="home app-main">
  12. <!-- 顶部轮播 -->
  13. <header-banner />
  14. <!-- 菜单导航 -->
  15. <menu-navigation :scrollTop="scrollTop" />
  16. <div class="home-main" :class="{ 'home-main-top': scrollTop > 473 }">
  17. <!-- 新闻最新一条 -->
  18. <div class="home-main-latest">
  19. <div class="home-main-latest-content">
  20. <div
  21. class="hmlc-title"
  22. @click="newsItemClick(latestNews)"
  23. >
  24. {{ latestNews.artTitle }}
  25. </div>
  26. <!-- <div class="hmlc-content" v-html="latestNews.artContent"></div> -->
  27. </div>
  28. </div>
  29. <div class="home-main-box">
  30. <!-- 新闻通知 -->
  31. <news-notice @getLastNews="getLastNews" />
  32. <!-- 政策资讯 -->
  33. <policy-information />
  34. <!-- 院校合作 -->
  35. <institutional-cooperation />
  36. <!-- 企业合作 -->
  37. <enterprise-cooperation />
  38. </div>
  39. </div>
  40. <!-- 友情链接 -->
  41. <friendship-link />
  42. <!-- 右侧操作 -->
  43. <div class="home-operation">
  44. <div class="home-operation-fixed">
  45. <div class="home-operation-fixed-item home-operation-fixed-item-1">
  46. <el-image
  47. class="image"
  48. :src="require('@/assets/images/search-icon.svg')"
  49. ></el-image>
  50. </div>
  51. <div class="home-operation-fixed-item">
  52. <el-image
  53. class="image"
  54. :src="require('@/assets/images/email-icon.svg')"
  55. @click="openWechatCode('email')"
  56. ></el-image>
  57. </div>
  58. <div class="home-operation-fixed-item">
  59. <el-image
  60. class="image"
  61. :src="require('@/assets/images/telephone-icon.svg')"
  62. @click="openWechatCode('phone')"
  63. ></el-image>
  64. </div>
  65. <div class="home-operation-fixed-item">
  66. <el-image
  67. class="image"
  68. :src="require('@/assets/images/weixin-icon.svg')"
  69. @click="openWechatCode('wechat')"
  70. ></el-image>
  71. </div>
  72. <div
  73. class="home-operation-fixed-item home-operation-fixed-item-last"
  74. @click="backToTop"
  75. >
  76. <el-image
  77. class="image"
  78. :src="require('@/assets/images/top-icon.svg')"
  79. ></el-image>
  80. </div>
  81. </div>
  82. </div>
  83. <!-- 微信二维码 -->
  84. <el-dialog
  85. class="wechat-dialog"
  86. :title="dialogObj.title"
  87. :visible.sync="dialogObj.open"
  88. width="380px"
  89. :before-close="handleCloseWechat"
  90. >
  91. <template v-if="dialogObj.type === 'wechat'">
  92. <div class="wechat-qrcode" ref="qrcode"></div>
  93. </template>
  94. <template v-if="dialogObj.type === 'phone'">
  95. <div class="phone-number">联系方式:{{ dialogObj.phone }}</div>
  96. </template>
  97. <template v-if="dialogObj.type === 'email'">
  98. <div class="phone-number">联系邮箱:{{ dialogObj.email }}</div>
  99. </template>
  100. <span slot="footer" class="dialog-footer">
  101. <el-button @click="handleCloseWechat">取 消</el-button>
  102. </span>
  103. </el-dialog>
  104. </div>
  105. </template>
  106. <script>
  107. import HeaderBanner from "./components/HeaderBanner";
  108. import MenuNavigation from "./components/MenuNavigation";
  109. import NewsNotice from "./components/NewsNotice.vue";
  110. import PolicyInformation from "./components/PolicyInformation";
  111. import InstitutionalCooperation from "./components/InstitutionalCooperation";
  112. import EnterpriseCooperation from "./components/EnterpriseCooperation";
  113. import FriendshipLink from "./components/FriendshipLink";
  114. import { getDictData } from "@/api/Dict";
  115. import QRCode from "qrcodejs2";
  116. export default {
  117. name: "HomeIndex",
  118. components: {
  119. HeaderBanner,
  120. MenuNavigation,
  121. NewsNotice,
  122. PolicyInformation,
  123. InstitutionalCooperation,
  124. EnterpriseCooperation,
  125. FriendshipLink,
  126. },
  127. data() {
  128. return {
  129. latestNews: {},
  130. scrollTop: 0,
  131. dialogObj: {
  132. open: false,
  133. title: "",
  134. url: "",
  135. phone: "",
  136. email: "",
  137. type: "wechat",
  138. },
  139. };
  140. },
  141. created() {
  142. this.getDict();
  143. },
  144. mounted() {
  145. const that = this;
  146. window.addEventListener("scroll", that.scrollHander);
  147. },
  148. destroyed() {
  149. window.removeEventListener("scroll", this.scrollHander);
  150. },
  151. methods: {
  152. scrollHander(e) {
  153. this.scrollTop = e.srcElement.scrollingElement.scrollTop;
  154. },
  155. /**
  156. * 获取字典数据
  157. * @date 2022-08-17
  158. * @returns {any}
  159. */
  160. getDict() {
  161. getDictData({ key: "gateway_home_function" }).then((res) => {
  162. res.data.length > 0 ? this.dialogObj.url = res.data[0].text : '';
  163. res.data.length > 1 ? this.dialogObj.phone = res.data[1].text : '';
  164. res.data.length > 2 ? this.dialogObj.email = res.data[2].text : '';
  165. });
  166. },
  167. /**
  168. * 最新一条新闻
  169. * @date 2022-08-30
  170. * @param {any} obj
  171. * @returns {any}
  172. */
  173. getLastNews(obj) {
  174. this.latestNews = obj;
  175. },
  176. /**
  177. * 跳转到指定页面
  178. * @date 2022-08-11
  179. * @param {any} path
  180. * @returns {any}
  181. */
  182. jumpPage(path, query) {
  183. if (path) {
  184. this.$router.push({ path, query });
  185. }
  186. },
  187. /**
  188. * 返回顶部
  189. * @date 2022-08-22
  190. * @returns {any}
  191. */
  192. backToTop() {
  193. cancelAnimationFrame(this.timer);
  194. const self = this;
  195. self.timer = requestAnimationFrame(function fn() {
  196. const oTop =
  197. document.body.scrollTop || document.documentElement.scrollTop;
  198. if (oTop > 0) {
  199. document.body.scrollTop = document.documentElement.scrollTop =
  200. oTop - 50;
  201. self.timer = requestAnimationFrame(fn);
  202. } else {
  203. cancelAnimationFrame(self.timer);
  204. }
  205. });
  206. },
  207. /**
  208. * 打开微信二维码
  209. * @date 2022-08-30
  210. * @returns {any}
  211. */
  212. openWechatCode(type) {
  213. this.dialogObj.open = true;
  214. this.dialogObj.type = type;
  215. switch (type) {
  216. case "email":
  217. this.dialogObj.title = "邮箱";
  218. break;
  219. case "phone":
  220. this.dialogObj.title = "联系方式";
  221. break;
  222. case "wechat":
  223. this.dialogObj.title = "移动端二维码";
  224. break;
  225. }
  226. if (this.dialogObj.type === "wechat") {
  227. this.$nextTick(() => {
  228. new QRCode(this.$refs.qrcode, {
  229. text: this.dialogObj.url, // url地址 文本等需要转换为二维码的内容
  230. width: 200,
  231. height: 200,
  232. colorDark: "#333333", // 二维码颜色
  233. colorLight: "#ffffff", // 二维码背景色
  234. correctLevel: QRCode.CorrectLevel.L, // 容错率,L/M/H
  235. });
  236. });
  237. }
  238. },
  239. /**
  240. * 关闭微信弹框
  241. * @date 2022-08-30
  242. * @returns {any}
  243. */
  244. handleCloseWechat() {
  245. if (this.dialogObj.type === "wechat") {
  246. this.$refs.qrcode.innerHTML = "";
  247. }
  248. this.dialogObj.open = false;
  249. },
  250. newsItemClick(item) {
  251. if (item.artLinkUrl) location.href = item.artLinkUrl;
  252. else
  253. this.jumpPage("newsdetails", {
  254. id: item.artId,
  255. type: "news",
  256. });
  257. },
  258. },
  259. };
  260. </script>
  261. <style lang="scss" scoped>
  262. .home {
  263. &-main {
  264. &-latest {
  265. background-color: #fff;
  266. &-content {
  267. width: 70%;
  268. margin: 0 auto;
  269. min-width: 600px;
  270. padding: 17px 0;
  271. .hmlc-title {
  272. font-size: 28px;
  273. color: #ff001a;
  274. text-align: center;
  275. margin-bottom: 10px;
  276. cursor: pointer;
  277. }
  278. .hmlc-content {
  279. font-size: 12px;
  280. line-height: 17px;
  281. overflow: hidden;
  282. text-overflow: ellipsis;
  283. text-overflow: -o-ellipsis-lastline;
  284. display: -webkit-box;
  285. -webkit-line-clamp: 2; /* 块元素显示的文本的行数 */
  286. line-clamp: 2;
  287. -webkit-box-orient: vertical; /* 设置或检索伸缩盒对象的子元素的排列方式 ,盒子行数根据高度来计算 */
  288. overflow-wrap: break-word; /* 设置div换行 */
  289. p {
  290. img {
  291. display: none !important;
  292. }
  293. }
  294. }
  295. }
  296. }
  297. }
  298. .home-main-top {
  299. margin-top: 104px;
  300. }
  301. &-operation {
  302. position: fixed;
  303. top: 50%;
  304. right: 0;
  305. margin-top: -138px;
  306. z-index: 1000;
  307. &-fixed {
  308. &-item {
  309. width: 70px;
  310. height: 70px;
  311. display: flex;
  312. justify-content: center;
  313. align-items: center;
  314. background: #416050;
  315. margin-bottom: 2px;
  316. cursor: pointer;
  317. &:nth-last-child(2) {
  318. margin-bottom: 0;
  319. }
  320. &:first-child,
  321. &:last-child {
  322. background: #73aa8d;
  323. }
  324. .image {
  325. width: 30px;
  326. height: 30px;
  327. }
  328. }
  329. &-item-last {
  330. height: 40px;
  331. .image {
  332. width: 15px;
  333. height: 15px;
  334. }
  335. }
  336. }
  337. }
  338. .wechat-qrcode {
  339. width: 200px;
  340. margin: 0 auto;
  341. }
  342. .wechat-dialog:deep(.el-dialog__footer) {
  343. text-align: center;
  344. }
  345. }
  346. </style>