陈帅 7 лет назад
Родитель
Сommit
f903f9aeaa

+ 1 - 0
.eslintignore

@@ -0,0 +1 @@
+/functions/mock

+ 5 - 0
.firebaserc

@@ -0,0 +1,5 @@
+{
+  "projects": {
+    "default": "antd-pro"
+  }
+}

+ 2 - 4
.gitignore

@@ -1,7 +1,7 @@
 # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
 
 # dependencies
-/node_modules
+node_modules
 # roadhog-api-doc ignore
 /src/utils/request-temp.js
 _roadhog-api-doc
@@ -20,11 +20,9 @@ yarn-error.log
 yarn.lock
 package-lock.json
 *bak
-<<<<<<< HEAD
 jsconfig.json
 .vscode
-=======
 
 # visual studio code 
 .history
->>>>>>> master
+*.log

+ 7 - 0
firebase.json

@@ -0,0 +1,7 @@
+{
+  "hosting": {
+    "public": "dist",
+    "rewrites": [{ "source": "/api/**", "function": "api" }],
+    "ignore": ["firebase.json", "**/.*", "**/node_modules/**"]
+  }
+}

+ 45 - 0
functions/index.js

@@ -0,0 +1,45 @@
+// [START functionsimport]
+const functions = require('firebase-functions');
+const express = require('express');
+const mock = require('./mock/index');
+
+const app = express();
+
+const sendData = (body, req, res) => {
+  if (!body) {
+    res.send('test');
+    return '';
+  }
+  if ('$body' in body) {
+    res.send(body.$body);
+    return;
+  }
+  if (typeof body === 'function') {
+    body(req, res);
+  }
+  res.send(body);
+};
+app.get('/api', (req, res) => {
+  const html = Object.keys(mock).map(url => {
+    return `<li><code>${url}</code></li>`;
+  });
+  res.send(`<ul>${html.join('')}</ul>`);
+});
+
+Object.keys(mock).forEach(url => {
+  const body = mock[url];
+  const urlParams = url.split(' ');
+
+  const path = urlParams[1];
+  const send = (req, res) => {
+    sendData(body, req, res);
+  };
+  if (urlParams[0] === 'GET') {
+    app.get(path, send);
+  }
+  if (urlParams[0] === 'POST') {
+    app.post(path, send);
+  }
+});
+
+exports.api = functions.https.onRequest(app);

Разница между файлами не показана из-за своего большого размера
+ 1784 - 0
functions/mock/geographic/city.json


+ 17 - 0
functions/mock/geographic/geographic.js

@@ -0,0 +1,17 @@
+function getJson(infoType) {
+  const json = require(`${__dirname}/${infoType}.json`);
+  return JSON.parse(json);
+}
+
+export function getProvince(req, res) {
+  res.json(getJson('province'));
+}
+
+export function getCity(req, res) {
+  res.json(getJson('city')[req.params.province]);
+}
+
+export default {
+  getProvince,
+  getCity,
+};

+ 138 - 0
functions/mock/geographic/province.json

@@ -0,0 +1,138 @@
+[
+  {
+    "name": "北京市",
+    "id": "110000"
+  },
+  {
+    "name": "天津市",
+    "id": "120000"
+  },
+  {
+    "name": "河北省",
+    "id": "130000"
+  },
+  {
+    "name": "山西省",
+    "id": "140000"
+  },
+  {
+    "name": "内蒙古自治区",
+    "id": "150000"
+  },
+  {
+    "name": "辽宁省",
+    "id": "210000"
+  },
+  {
+    "name": "吉林省",
+    "id": "220000"
+  },
+  {
+    "name": "黑龙江省",
+    "id": "230000"
+  },
+  {
+    "name": "上海市",
+    "id": "310000"
+  },
+  {
+    "name": "江苏省",
+    "id": "320000"
+  },
+  {
+    "name": "浙江省",
+    "id": "330000"
+  },
+  {
+    "name": "安徽省",
+    "id": "340000"
+  },
+  {
+    "name": "福建省",
+    "id": "350000"
+  },
+  {
+    "name": "江西省",
+    "id": "360000"
+  },
+  {
+    "name": "山东省",
+    "id": "370000"
+  },
+  {
+    "name": "河南省",
+    "id": "410000"
+  },
+  {
+    "name": "湖北省",
+    "id": "420000"
+  },
+  {
+    "name": "湖南省",
+    "id": "430000"
+  },
+  {
+    "name": "广东省",
+    "id": "440000"
+  },
+  {
+    "name": "广西壮族自治区",
+    "id": "450000"
+  },
+  {
+    "name": "海南省",
+    "id": "460000"
+  },
+  {
+    "name": "重庆市",
+    "id": "500000"
+  },
+  {
+    "name": "四川省",
+    "id": "510000"
+  },
+  {
+    "name": "贵州省",
+    "id": "520000"
+  },
+  {
+    "name": "云南省",
+    "id": "530000"
+  },
+  {
+    "name": "西藏自治区",
+    "id": "540000"
+  },
+  {
+    "name": "陕西省",
+    "id": "610000"
+  },
+  {
+    "name": "甘肃省",
+    "id": "620000"
+  },
+  {
+    "name": "青海省",
+    "id": "630000"
+  },
+  {
+    "name": "宁夏回族自治区",
+    "id": "640000"
+  },
+  {
+    "name": "新疆维吾尔自治区",
+    "id": "650000"
+  },
+  {
+    "name": "台湾省",
+    "id": "710000"
+  },
+  {
+    "name": "香港特别行政区",
+    "id": "810000"
+  },
+  {
+    "name": "澳门特别行政区",
+    "id": "820000"
+  }
+]

Разница между файлами не показана из-за своего большого размера
+ 1197 - 0
functions/mock/index.js


+ 20 - 0
functions/package.json

@@ -0,0 +1,20 @@
+{
+  "name": "functions",
+  "description": "Cloud Functions for Firebase",
+  "scripts": {
+    "serve": "firebase serve --only functions",
+    "shell": "firebase functions:shell",
+    "start": "npm run shell",
+    "deploy": "firebase deploy --only functions",
+    "logs": "firebase functions:log"
+  },
+  "dependencies": {
+    "cors": "^2.8.1",
+    "express": "^4.16.3",
+    "firebase-admin": "^5.12.1",
+    "firebase-functions": "^1.0.3",
+    "mockjs": "^1.0.1-beta3",
+    "moment": "^2.22.2"
+  },
+  "private": true
+}

+ 1 - 0
package.json

@@ -27,6 +27,7 @@
     "bizcharts": "^3.1.10",
     "bizcharts-plugin-slider": "^2.0.3",
     "classnames": "^2.2.6",
+    "cors": "^2.8.4",
     "dva": "^2.3.1",
     "dva-loading": "^2.0.3",
     "enquire-js": "^0.2.1",