xinfeng 6 anni fa
parent
commit
a90d24b730
6 ha cambiato i file con 189 aggiunte e 148 eliminazioni
  1. 111 94
      nuxt.config.js
  2. 2 0
      package.json
  3. 8 37
      pages/salary/index.vue
  4. 20 13
      plugins/deviceType.js
  5. 15 0
      plugins/vconsole.js
  6. 33 4
      yarn.lock

+ 111 - 94
nuxt.config.js

@@ -1,118 +1,122 @@
 const pkg = require('./package');
+const cheerio = require('cheerio')
 
 module.exports = {
-	mode: 'universal',
-
-	env: {
-		baseUrl: process.env.NODE_ENV == 'development' ? 'https://dev.test.proginn.com' : 'https://www.proginn.com',
-		jishuBaseUrl:
-			process.env.NODE_ENV == 'development'
-				? 'https://dev.test-jishuin.proginn.com'
-				: 'https://jishuin.proginn.com'
-	},
-
-	/**
+  mode: 'universal',
+  
+  env: {
+    baseUrl: process.env.NODE_ENV == 'development' ? 'https://dev.test.proginn.com' : 'https://www.proginn.com',
+    jishuBaseUrl:
+      process.env.NODE_ENV == 'development'
+        ? 'https://dev.test-jishuin.proginn.com'
+        : 'https://jishuin.proginn.com'
+  },
+  
+  /**
    * 打包文件
    */
-	build : {
-		vendor: [ 'element-ui' ]
-	},
-
-	server: {
-		host: `0.0.0.0`,
-		port: 3000
-	},
-
-	/*
+  build: {
+    vendor: [ 'element-ui' ],
+  },
+  
+  server: {
+    host: `0.0.0.0`,
+    port: 3000
+  },
+  
+  /*
   ** Headers of the page
   */
-	head: {
-		title: '程序员客栈',
-		meta: [
-			{ charset: 'utf-8' },
-			{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
-			{ name: 'baidu-site-verification', content: '7IbkIN9Kwp' },
-			{ 'http-equiv': 'X-UA-Compatible', content: 'IE=edge,chrome=1' },
-			// hid: 'x', 可在页面内覆盖这里
-			{ name: 'robots', content: 'noindex,follow' },
-			{ name: 'description', content: pkg.description },
-			{ 'http-equiv': 'Cache-Control', content: 'no-transform' },
-			{ 'http-equiv': 'Cache-Control', content: 'no-siteapp' }
-		],
-		link: [ { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' } ]
-	},
-
-	/*
+  head: {
+    title: '程序员客栈',
+    meta: [
+      { charset: 'utf-8' },
+      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
+      { name: 'baidu-site-verification', content: '7IbkIN9Kwp' },
+      { 'http-equiv': 'X-UA-Compatible', content: 'IE=edge,chrome=1' },
+      // hid: 'x', 可在页面内覆盖这里
+      { name: 'robots', content: 'noindex,follow' },
+      { name: 'description', content: pkg.description },
+      { 'http-equiv': 'Cache-Control', content: 'no-transform' },
+      { 'http-equiv': 'Cache-Control', content: 'no-siteapp' }
+    ],
+    link: [ { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' } ]
+  },
+  
+  /*
   ** Customize the progress-bar color
   */
-	loading: { color: '#fff' },
-
-	/*
+  loading: { color: '#fff' },
+  
+  /*
   ** Global CSS
   */
-	css: [ '@/assets/css/common.css', '@/assets/css/special.css', 'swiper/dist/css/swiper.css' ],
-
-	/*
+  css: [ '@/assets/css/common.css', '@/assets/css/special.css', 'swiper/dist/css/swiper.css' ],
+  
+  /*
   ** Plugins to load before mounting the App
   */
-	plugins: [
-		'plugins/common',
-		'plugins/element',
-		// 'plugins/http',
-		'plugins/nuxtAxios',
+  plugins: [
+    'plugins/common',
+    'plugins/element',
+    // 'plugins/http',
+    'plugins/nuxtAxios',
     'plugins/deviceType',
-		{
-			src:'plugins/rem',
-			ssr: false
-		},
-		{
-			src: "plugins/vue-swiper.js",
-			ssr: false
-		},
-		{
-			src: "plugins/g2.js",
-			ssr: false
-		}
-	],
-	/*
+    {
+      src: 'plugins/rem',
+      ssr: false
+    },
+    {
+      src: 'plugins/vconsole',
+      ssr: false
+    },
+    {
+      src: "plugins/vue-swiper.js",
+      ssr: false
+    },
+    {
+      src: "plugins/g2.js",
+      ssr: false
+    }
+  ],
+  /*
   ** Axios module configuration
   */
-	axios: {
-		// See http://github.com/nuxt-community/axios-module#options
-		proxy: process.env.NODE_ENV === 'development',
-		// http: true,
-		progress: true,
-		// baseURL: process.env.BASE_URL || '',
-		// browserBaseURL: '',
-		timeout: 15000,
-		credentials: true,
-		proxyHeaders: true
-		// debug: true
-	},
-	/**
+  axios: {
+    // See http://github.com/nuxt-community/axios-module#options
+    proxy: process.env.NODE_ENV === 'development',
+    // http: true,
+    progress: true,
+    // baseURL: process.env.BASE_URL || '',
+    // browserBaseURL: '',
+    timeout: 15000,
+    credentials: true,
+    proxyHeaders: true
+    // debug: true
+  },
+  /**
    * Proxy
    */
-	proxy: [
-		[ '/api', { target: 'https://dev.test.proginn.com', changeOrigin: true } ],
-		[ '/file/proxyUpload', { target: 'https://dev.test.proginn.com', changeOrigin: true } ],
-		[ '/upload_image', { target: 'https://dev.test-jishuin.proginn.com', changeOrigin: true } ],
-		[ '/image', { target: 'https://stacdn.proginn.com', changeOrigin: true } ]
-	],
-
-	/*
+  proxy: [
+    [ '/api', { target: 'https://dev.test.proginn.com', changeOrigin: true } ],
+    [ '/file/proxyUpload', { target: 'https://dev.test.proginn.com', changeOrigin: true } ],
+    [ '/upload_image', { target: 'https://dev.test-jishuin.proginn.com', changeOrigin: true } ],
+    [ '/image', { target: 'https://stacdn.proginn.com', changeOrigin: true } ]
+  ],
+  
+  /*
   ** Nuxt.js modules
   */
-	modules: [ '@nuxtjs/axios', '@nuxtjs/proxy' ],
-
-	/*
+  modules: [ '@nuxtjs/axios', '@nuxtjs/proxy' ],
+  
+  /*
   ** Build configuration
   */
-	build: {
-		/*
+  build: {
+    /*
     ** You can extend webpack config here
     */
     extractCSS: { //提取html中的 css到文件
-      allChunks: true,
       splitChunks: {
         cacheGroups: {
           styles: {
@@ -124,8 +128,21 @@ module.exports = {
         }
       }
     },
-		extend(config, ctx) {
-			console.log(config);
-		}
-	}
+    extend(config, ctx) {
+      console.log(config);
+    }
+  },
+  
+  hooks: {
+    render: {
+      route(url, result, context) {
+        if (context.nuxt.state.deviceType.spider) {
+          const doc = cheerio.load(result.html);
+          doc(`body script`).remove();
+          doc(`head style`).remove();
+          result.html = doc.html();
+        }
+      },
+    }
+  },
 };

+ 2 - 0
package.json

@@ -31,10 +31,12 @@
     "qs": "^6.8.0",
     "sass-loader": "^7.1.0",
     "style-loader": "^0.23.1",
+    "vconsole": "^3.3.4",
     "vue-awesome-swiper": "^3.1.3",
     "vue-quill-editor": "^3.0.6"
   },
   "devDependencies": {
+    "cheerio": "^1.0.0-rc.3",
     "less": "^3.9.0",
     "less-loader": "^5.0.0",
     "nodemon": "^1.18.9"

+ 8 - 37
pages/salary/index.vue

@@ -1,6 +1,6 @@
 <template>
   <div>
-    <div class="wrapper pc" v-if="screenWidth > 960">
+    <div class="wrapper pc" v-if="!mobile">
       <div class="header">
         <div class="bgImage">
           <img src="@/assets/img/salary/background.png" alt="">
@@ -117,15 +117,13 @@ export default {
         },
         {
           name: "descrption",
-          content:
-            "程序员客栈提供全国每个城市程序员岗位工资查询,帮助每一位程序员找到合适的工作,让每一个有程序员招聘需求的企业利用合适的费用找到合适的人才。"
+          content: "程序员客栈提供全国每个城市程序员岗位工资查询,帮助每一位程序员找到合适的工作,让每一个有程序员招聘需求的企业利用合适的费用找到合适的人才。"
         }
       ]
     };
   },
   data() {
     return {
-      screenWidth: 0,
       cityChart: [],
       jobChart: [],
       jobList: [],
@@ -140,7 +138,7 @@ export default {
       searchCity: ""
     };
   },
-  async asyncData ({ $axios, req, res }) {
+  async asyncData ({ $axios, req, res, app }) {
     // 请检查您是否在服务器端
     // 使用 req 和 res
     console.log(req)
@@ -177,44 +175,22 @@ export default {
         cityTick,
         jobTick,
         searchJob,
-        searchCity
+        searchCity,
+        mobile: app.$deviceType.isMobile(),
       }
     }
 
-    return {}
+    return {
+      mobile: app.$deviceType.isMobile()
+    }
   },
   mounted() {
-    this.screenWidth = window.screen.width;
     this.$nextTick(() => {
       this.getData();
     });
   },
   methods: {
     async getData() {
-      // let res = await this.$axios.$post("/api/salary/index_info");
-
-      // this.cityChart = res.data.sortOfCity;
-      // this.jobChart = res.data.sortOfJob;
-      // this.jobList = res.data.allJobType;
-      // this.city = res.data.sortOfCity[0].city;
-      // this.citySalary = res.data.sortOfCity[0].salary;
-      // this.job = res.data.sortOfJob[0].job;
-      // this.jobSalary = res.data.sortOfJob[0].salary;
-      // this.cityTick = res.data.cityTick;
-      // this.jobTick = res.data.jobTick;
-      // this.cityList = res.data.cityList;
-      // this.searchJob = res.data.allJobType[0].job_slug;
-      // this.searchCity = res.data.cityList[0].city_slug;
-
-      // console.log(this.cityList);
-
-      // for (let i = 0; i < this.cityChart.length; i++) {
-      //   this.cityChart[i].salary = parseInt(this.cityChart[i].salary);
-      // }
-      // for (let i = 0; i < this.jobChart.length; i++) {
-      //   this.jobChart[i].salary = parseInt(this.jobChart[i].salary);
-      // }
-
       //开发者薪资排行城市TOP10
       const chart1 = new G2.Chart({
         container: "city-chart",
@@ -256,11 +232,6 @@ export default {
         this.$message("请输入查询岗位名称");
         return false;
       }
-      // this.searchJob = this.searchJob.replace(/c#/, "c%23");
-      // this.searchJob = this.searchJob.replace(/c\+\+*/, "c%24");
-      // this.$router.push(
-      //   "/salary/detail?job=" + this.searchJob + "&city=" + this.searchCity
-      // );
       window.location.href = `/salary/${this.searchCity}-${this.searchJob}/`.replace('c#', 'c%23');
     },
     inVal(val) {

+ 20 - 13
plugins/deviceType.js

@@ -5,19 +5,20 @@ export default function ({req}, inject) {
   deviceType.pc = false
   deviceType.ios = false
   deviceType.wx = false
-  deviceType.ua = ''
-  deviceType.cookie = ''
   deviceType.app = false
+  deviceType.spider = false
+  
+  let cookie = '', ua = ''
   
   /** 通过UA判断设备类型 **/
   if (req && req.headers) {
-    deviceType.ua = req && req.headers && req.headers['user-agent'] || ''
+    ua = req && req.headers && req.headers['user-agent'] || ''
   } else if (window && window.navigator){
-    deviceType.ua = window.navigator.userAgent
+    ua = window.navigator.userAgent
   }
-  if (/(iPhone|iPad|iPod|iOS)/i.test(deviceType.ua)) {
+  if (/(iPhone|iPad|iPod|iOS)/i.test(ua)) {
     deviceType.ios = true
-  } else if (/(Android)/i.test(deviceType.ua)) {
+  } else if (/(Android)/i.test(ua)) {
     deviceType.android = true
   } else {
     deviceType.pc = true
@@ -25,21 +26,26 @@ export default function ({req}, inject) {
   
   /** 通过cookie 判断是不是APP **/
   if (req && req.headers && req.headers.cookie) {
-    deviceType.cookie = req.headers.cookie
+    cookie = req.headers.cookie
   } else if (document){
-    deviceType.cookie = document.cookie
+    cookie = document.cookie
   }
-  if (/(x_app)/i.test(deviceType.cookie)) {
+  if (/(x_app)/i.test(cookie)) {
     deviceType.app = true
   }  else {
     deviceType.app = false
   }
   
   /** 判断是不是 微信 **/
-  if (/(MicroMessenger)/i.test(deviceType.ua)) {
+  if (/(MicroMessenger)/i.test(ua)) {
     deviceType.wx = true
   }
   
+  /**  判断是不是 蜘蛛 **/
+  if (/(spider)/i.test(ua)) {
+    deviceType.spider = true
+  }
+  
   deviceType.isIos = function() {
     return deviceType.ios
   }
@@ -59,8 +65,9 @@ export default function ({req}, inject) {
   deviceType.isWx = function() {
     return deviceType.wx
   }
+  console.log('deviceType', deviceType)
+  // inject('deviceType', deviceType)
   
-  console.log('deviceType:', deviceType)
-  
-  inject('deviceType', deviceType)
+  inject && inject('deviceType', deviceType)
+  return deviceType
 }

+ 15 - 0
plugins/vconsole.js

@@ -0,0 +1,15 @@
+/**
+ * vconsole
+ */
+import vconsole from 'vconsole'
+import deviceType from './deviceType'
+try {
+  let showVconsole = ['local.proginn.com:3000', 'dev.test.proginn.com', 'app.test.proginn.com']
+  let host = location.host
+  let device = new deviceType({},null) || {}
+  if (showVconsole.indexOf(host) !== -1 && !device.pc) {
+    new vconsole()
+  }
+} catch (e) {
+  console.log('加载vconsole出错', e)
+}

+ 33 - 4
yarn.lock

@@ -988,6 +988,11 @@
     mustache "^2.3.0"
     stack-trace "0.0.10"
 
+"@types/node@*":
+  version "13.1.2"
+  resolved "https://registry.npm.taobao.org/@types/node/download/@types/node-13.1.2.tgz?cache=0&sync_timestamp=1577727780099&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40types%2Fnode%2Fdownload%2F%40types%2Fnode-13.1.2.tgz#fe94285bf5e0782e1a9e5a8c482b1c34465fa385"
+  integrity sha1-/pQoW/XgeC4anlqMSCscNEZfo4U=
+
 "@types/q@^1.5.1":
   version "1.5.2"
   resolved "https://registry.npm.taobao.org/@types/q/download/@types/q-1.5.2.tgz#690a1475b84f2a884fd07cd797c00f5f31356ea8"
@@ -1874,6 +1879,18 @@ check-types@^7.3.0:
   version "7.4.0"
   resolved "https://registry.npm.taobao.org/check-types/download/check-types-7.4.0.tgz#0378ec1b9616ec71f774931a3c6516fad8c152f4"
 
+cheerio@^1.0.0-rc.3:
+  version "1.0.0-rc.3"
+  resolved "https://registry.npm.taobao.org/cheerio/download/cheerio-1.0.0-rc.3.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fcheerio%2Fdownload%2Fcheerio-1.0.0-rc.3.tgz#094636d425b2e9c0f4eb91a46c05630c9a1a8bf6"
+  integrity sha1-CUY21CWy6cD065GkbAVjDJoai/Y=
+  dependencies:
+    css-select "~1.2.0"
+    dom-serializer "~0.1.1"
+    entities "~1.1.1"
+    htmlparser2 "^3.9.1"
+    lodash "^4.15.0"
+    parse5 "^3.0.1"
+
 chokidar@^2.0.2, chokidar@^2.1.5:
   version "2.1.6"
   resolved "https://registry.npm.taobao.org/chokidar/download/chokidar-2.1.6.tgz#b6cad653a929e244ce8a834244164d241fa954c5"
@@ -2340,7 +2357,7 @@ css-select-base-adapter@^0.1.1:
   version "0.1.1"
   resolved "https://registry.npm.taobao.org/css-select-base-adapter/download/css-select-base-adapter-0.1.1.tgz#3b2ff4972cc362ab88561507a95408a1432135d7"
 
-css-select@^1.1.0:
+css-select@^1.1.0, css-select@~1.2.0:
   version "1.2.0"
   resolved "https://registry.npm.taobao.org/css-select/download/css-select-1.2.0.tgz#2b3a110539c5355f1cd8d314623e870b121ec858"
   dependencies:
@@ -2665,7 +2682,7 @@ dom-converter@^0.2:
   dependencies:
     utila "~0.4"
 
-dom-serializer@0:
+dom-serializer@0, dom-serializer@~0.1.1:
   version "0.1.1"
   resolved "https://registry.npm.taobao.org/dom-serializer/download/dom-serializer-0.1.1.tgz#1ec4059e284babed36eec2941d4a970a189ce7c0"
   dependencies:
@@ -2810,7 +2827,7 @@ enhanced-resolve@^4.1.0:
     memory-fs "^0.4.0"
     tapable "^1.0.0"
 
-entities@^1.1.1:
+entities@^1.1.1, entities@~1.1.1:
   version "1.1.2"
   resolved "https://registry.npm.taobao.org/entities/download/entities-1.1.2.tgz#bdfa735299664dfafd34529ed4f8522a275fea56"
 
@@ -3591,7 +3608,7 @@ html-webpack-plugin@^3.2.0:
     toposort "^1.0.0"
     util.promisify "1.0.0"
 
-htmlparser2@^3.3.0:
+htmlparser2@^3.3.0, htmlparser2@^3.9.1:
   version "3.10.1"
   resolved "https://registry.npm.taobao.org/htmlparser2/download/htmlparser2-3.10.1.tgz#bd679dc3f59897b6a34bb10749c855bb53a9392f"
   dependencies:
@@ -5007,6 +5024,13 @@ parse-json@^4.0.0:
     error-ex "^1.3.1"
     json-parse-better-errors "^1.0.1"
 
+parse5@^3.0.1:
+  version "3.0.3"
+  resolved "https://registry.npm.taobao.org/parse5/download/parse5-3.0.3.tgz?cache=0&sync_timestamp=1573036827948&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fparse5%2Fdownload%2Fparse5-3.0.3.tgz#042f792ffdd36851551cf4e9e066b3874ab45b5c"
+  integrity sha1-BC95L/3TaFFVHPTp4Gazh0q0W1w=
+  dependencies:
+    "@types/node" "*"
+
 parseurl@~1.3.3:
   version "1.3.3"
   resolved "https://registry.npm.taobao.org/parseurl/download/parseurl-1.3.3.tgz#9da19e7bee8d12dff0513ed5b76957793bc2e8d4"
@@ -7200,6 +7224,11 @@ vary@~1.1.2:
   version "1.1.2"
   resolved "https://registry.npm.taobao.org/vary/download/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc"
 
+vconsole@^3.3.4:
+  version "3.3.4"
+  resolved "https://registry.npm.taobao.org/vconsole/download/vconsole-3.3.4.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fvconsole%2Fdownload%2Fvconsole-3.3.4.tgz#a7dacd8887b3d3e902e8d18425cda56c34e77f51"
+  integrity sha1-p9rNiIez0+kC6NGEJc2lbDTnf1E=
+
 vendors@^1.0.0:
   version "1.0.3"
   resolved "https://registry.npm.taobao.org/vendors/download/vendors-1.0.3.tgz#a6467781abd366217c050f8202e7e50cc9eef8c0"