Homepage.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <template>
  2. <div class="home-wrapper">
  3. <div class="nav" stype="height:500px">
  4. <!--搜索框-->
  5. <el-row class="search-nav" style="padding: 30px 0 20px 0">
  6. <el-col :span="6">
  7. <div class="pull-left">
  8. <img class="logo-img" src="../../assets/image/logo-transparent.png" :to="'/home'"/>
  9. <span class="logo-title">{{ logoTitle }}</span>
  10. </div>
  11. </el-col>
  12. <el-col :span="12">
  13. <div class="search-nav">
  14. <div id="search-block ">
  15. <el-tabs v-model="searchType" type="card" @tab-click="handleTypeClick">
  16. <el-tab-pane v-for="item in searchTypeArr" v-if="item.value!=='all'" :label="item.name"
  17. :name="item.value" :key="item.value"></el-tab-pane>
  18. </el-tabs>
  19. <div class="search-input">
  20. <el-input ref="searchInput" placeholder="请输入内容" v-model="searchVal" class="input-with-select">
  21. <el-button class="search-button" slot="append" type="primary" @click="handleSearchData">搜索</el-button>
  22. </el-input>
  23. </div>
  24. </div>
  25. </div>
  26. </el-col>
  27. <el-col :span="6">
  28. <el-button type="primary pull-right" class="releaseBtn" @click="checkLogin()">免费发布众测需求</el-button>
  29. </el-col>
  30. </el-row>
  31. <!--TabNav-->
  32. <el-tabs v-model="currTab" @tab-click="handleTabClick" class="square-tab">
  33. <el-tab-pane v-for="item in homeTabArr.menuArr1" :label="item.label" :name="item.name"
  34. :key="item.name"></el-tab-pane>
  35. <el-tab-pane v-for="item in homeTabArr.menuArr2" :label="item.name" :name="item.code"
  36. :key="item.code"></el-tab-pane>
  37. <el-tab-pane v-for="item in homeTabArr.menuArr3" :label="item.label" :name="item.name"
  38. :key="item.name"></el-tab-pane>
  39. </el-tabs>
  40. <div>
  41. </div>
  42. </div>
  43. <div class="home-page container">
  44. <el-row>
  45. <el-col :span="19" class="test-type-wrapper">
  46. <TestMenu :testTypeList="homeData.testTypeList" v-if="HOME_DISPLAY.test_menu"></TestMenu>
  47. <TestCard :applicationTypeList="homeData.applicationTypeList" v-if="HOME_DISPLAY.test_card"></TestCard>
  48. <el-row style="margin-top: 10px" v-if="HOME_DISPLAY.resource_and_tool">
  49. <ResourceAndTool :resourceList="homeDataNoCache.resourceList"></ResourceAndTool>
  50. </el-row>
  51. <el-row v-if="HOME_DISPLAY.brand_card">
  52. <BrandCard :residentAgencyList=homeData.residentAgencyList></BrandCard>
  53. </el-row>
  54. </el-col>
  55. <el-col :span="5" class="homepage-right-modules">
  56. <LoginCard v-if="HOME_DISPLAY.login_card"/>
  57. <HotCrowd :applicationTypeRank="homeDataNoCache.applicationTypeRank" v-if="HOME_DISPLAY.hot_crowd"/>
  58. <HotAgency :agencyRank="homeDataNoCache.agencyRank" v-if="HOME_DISPLAY.hot_agency"/>
  59. <HotUser :userRank="homeDataNoCache.userRank" v-if="HOME_DISPLAY.hot_user"/>
  60. <HotContest :competitionList="homeData.competitionList" v-if="HOME_DISPLAY.hot_crowd"/>
  61. </el-col>
  62. </el-row>
  63. <InstitutionCard v-if="HOME_DISPLAY.institution_card"></InstitutionCard>
  64. </div>
  65. </div>
  66. </template>
  67. <script>
  68. // import commonData from '../../constants/tabMenu'
  69. import SearchBar from '../../components/commons/SearchBar'
  70. import TestMenu from './TestMenu'
  71. import LoginCard from './LoginCard'
  72. import BrandCard from './BrandCard'
  73. import ResourceAndTool from './ResourceAndTool'
  74. import TestCard from './TestCard'
  75. import InstitutionCard from './InstitutionCard'
  76. import HotCrowd from './HotCrowd'
  77. import HotAgency from './HotAgency'
  78. import HotUser from './HotUser'
  79. import HotContest from './HotContest'
  80. import PopularProject from '../Square/PopularProject'
  81. import Http from '@/js/http.js'
  82. import {mapGetters} from 'vuex'
  83. import Waterfall from 'vue-waterfall/lib/waterfall'
  84. import WaterfallSlot from 'vue-waterfall/lib/waterfall-slot'
  85. import {getAllFields, storageGet} from '@/js/index.js'
  86. import {notify} from "../../constants";
  87. import Apis from '@/js/api'
  88. import {logoTitle, home_searchTypeArr, home_homeTabArr_left,
  89. home_homeTabArr_right,home_homeTabArr_default,HOME_DISPLAY} from "../../config";
  90. // console.log(commonData);
  91. export default {
  92. name: 'Homepage',
  93. components: {
  94. HotCrowd,
  95. HotContest,
  96. HotUser,
  97. HotAgency,
  98. InstitutionCard,
  99. SearchBar,
  100. TestMenu,
  101. PopularProject,
  102. LoginCard,
  103. TestCard,
  104. BrandCard,
  105. ResourceAndTool,
  106. Waterfall,
  107. WaterfallSlot
  108. // vueWaterfallEasy
  109. },
  110. data() {
  111. return {
  112. logoTitle,
  113. HOME_DISPLAY,
  114. user: {},
  115. isLogin: false,
  116. loading: false,
  117. searchType: '0',
  118. searchTypeArr: home_searchTypeArr,
  119. searchVal: '',
  120. homeTabArr: {
  121. menuArr1: home_homeTabArr_left,
  122. menuArr2: [{code: '', name: ''}],
  123. menuArr3: home_homeTabArr_right
  124. },
  125. homeData: {},
  126. homeDataNoCache: {},
  127. currTab: home_homeTabArr_default
  128. }
  129. },
  130. computed: {
  131. ...mapGetters(['getUserInfo'])
  132. },
  133. methods: {
  134. loadData() {
  135. this.showLoading();
  136. if (storageGet('user') != null) {
  137. this.isLogin = true;
  138. }
  139. this.setFields();
  140. let p1 = new Promise((resolve, reject) => {
  141. Http.get('/api/common/index/info/cache').then((res) => {
  142. this.homeData = res.data;
  143. // this.homeData.applicationTypeList.map((item)=>{
  144. // item.height = (item.testTypeList.length / 2) * 24 + 100;
  145. // return item;
  146. // })
  147. resolve(res.data);
  148. }).catch((error) => {
  149. notify('error', error.data)
  150. reject(error)
  151. })
  152. });
  153. let p2 = new Promise((resolve, reject) => {
  154. Http.get('/api/common/index/info/nocache').then((res) => {
  155. this.homeDataNoCache = res.data;
  156. resolve(res.data);
  157. }).catch((error) => {
  158. notify('error', error.data)
  159. reject(error)
  160. })
  161. });
  162. Promise.all([p1, p2]).then((result) => {
  163. this.hideLoading();
  164. }).catch((error) => {
  165. notify('error', error.data)
  166. })
  167. },
  168. setFields() {
  169. getAllFields().then((res) => {
  170. this.homeTabArr.menuArr2 = res
  171. })
  172. },
  173. checkLogin() {
  174. this.checkCreateProjectAuth();
  175. },
  176. checkCreateProjectAuth() {
  177. if (!this.isLogin) {
  178. notify('warning', '请登录后访问');
  179. } else if (this.isLogin) {
  180. Http.get(Apis.USER.IS_PART.replace('{userId}', this.user.id)).then((res) => {
  181. this.$router.push('/project/create');
  182. }).catch((error) => {
  183. notify('error', error)
  184. })
  185. }
  186. },
  187. handleTabClick(tab) {
  188. this.currTab = tab.name;
  189. // console.log(this.currTab + " " + tab.index + " " + tab.name );
  190. for (let i = 0; i < this.homeTabArr.menuArr3.length; i++) {
  191. if (this.currTab === this.homeTabArr.menuArr3[i].name) {
  192. this.$router.push(this.homeTabArr.menuArr3[i].linkTo);
  193. }
  194. }
  195. for (let i = 0; i < this.homeTabArr.menuArr2.length; i++) {
  196. if (this.currTab === this.homeTabArr.menuArr2[i].code) {
  197. this.$router.push('/field/detail');
  198. }
  199. }
  200. this.$router.push(this.homeTabArr.menuArr1[Number(tab.index)] && this.homeTabArr.menuArr1[Number(tab.index)].linkTo);
  201. },
  202. handleTypeClick(tab, e) {
  203. this.searchType = tab.name;
  204. // e.target.style.backgroundColor = $color-primary
  205. this.$refs.searchInput.focus()
  206. },
  207. handleSearchData() {
  208. if (this.searchType == 0) {
  209. this.$router.push({
  210. name: 'Square',
  211. params: {searchVal: this.searchVal, searchType: "project", currTab: "project"}
  212. });
  213. } else if (this.searchType == 1) {
  214. this.$router.push({name: 'AgencyList', params: {searchVal: this.searchVal}});
  215. } else if (this.searchType == 2) {
  216. this.$router.push({name: 'ResourceList', params: {searchVal: this.searchVal}});
  217. } else if (this.searchType == 3) {
  218. this.$router.push({name: 'ExpertList', params: {searchVal: this.searchVal}});
  219. }
  220. },
  221. showLoading() {
  222. this.loading = true
  223. },
  224. hideLoading() {
  225. this.loading = false
  226. },
  227. setUserInfo() {
  228. this.user = storageGet('user') && storageGet('user').userVO;
  229. }
  230. },
  231. mounted() {
  232. this.setUserInfo();
  233. this.loadData();
  234. this.$refs.searchInput.focus()
  235. },
  236. watch: {
  237. getUserInfo(val) {
  238. this.setUserInfo();
  239. this.loadData();
  240. }
  241. }
  242. }
  243. </script>
  244. <style lang="scss">
  245. @import "../../style/search-nav.scss";
  246. .home-wrapper {
  247. /deep/ .square-tab .el-tabs__item {
  248. font-size: 16px !important;
  249. margin-right: 0px !important;
  250. }
  251. /deep/ .login-card .popular-list {
  252. padding: 0 10px !important;
  253. }
  254. .home-page {
  255. padding: 15px 0;
  256. }
  257. .test-type-wrapper {
  258. padding-right: 15px;
  259. margin-bottom: 15px;
  260. }
  261. .homepage-right-modules {
  262. .login-card .el-card__body {
  263. padding: 10px !important;
  264. }
  265. .popular-card .el-card__header {
  266. padding: 10px !important;
  267. }
  268. .popular-card .el-card__body {
  269. padding: 10px !important;
  270. }
  271. }
  272. }
  273. </style>