liyongli пре 3 година
родитељ
комит
ee5561155c
6 измењених фајлова са 119 додато и 31 уклоњено
  1. 0 8
      public/index.html
  2. 3 1
      src/App.vue
  3. 39 17
      src/api/index.js
  4. 1 1
      src/utils/request.js
  5. 49 0
      src/utils/requestOrther.js
  6. 27 4
      src/views/Appointment.vue

+ 0 - 8
public/index.html

@@ -8,13 +8,6 @@
     <link rel="icon" href="<%= BASE_URL %>favicon.ico">
     <script src="//cdn.bootcdn.net/ajax/libs/eruda/2.4.1/eruda.min.js"></script>
     <script>eruda.init();</script>
-    <script src="https://djweb.smcic.net/gouju/js/jquery-2.1.0.js"></script>
-    <!--导入原生js库-->
-    <!-- <script src="http://cmp/v1.0.0/js/cordova/__CMPSHELL_PLATFORM__/cordova.js"></script>
-    <script src="http://cmp/v1.0.0/js/cordova/cordova-plugins.js"></script> -->
-    <!--导入cmp.js-->
-    <!-- <script src="http://cmp/v/js/cmp-i18n.js"></script>
-    <script src="http://cmp/v/js/cmp.js"></script> -->
     <title>
         <%= htmlWebpackPlugin.options.title %>
     </title>
@@ -28,5 +21,4 @@
     <div id="app"></div>
     <!-- built files will be auto injected -->
 </body>
-
 </html>

+ 3 - 1
src/App.vue

@@ -9,7 +9,9 @@ export default {
   name: "App",
   methods: {
   },
-  mounted() {},
+  mounted() {
+    localStorage.token = "";
+  },
   components: {
   },
 };

+ 39 - 17
src/api/index.js

@@ -1,4 +1,5 @@
 import ajax from "../utils/request.js";
+import requestOrther from "../utils/requestOrther.js";
 
 /**
  * 商品列表
@@ -29,19 +30,19 @@ export function orderList(data) {
  * @returns {AjaxPromise}
  */
 export function apply(data) {
-    return ajax({
-      url: "/orders/add-app",
-      method: "post",
-      data,
-    });
-  }
-  export function applyreal(data) {
-    return ajax({
-      url: "/orders/add-house",
-      method: "post",
-      data,
-    });
-  }
+  return ajax({
+    url: "/orders/add-app",
+    method: "post",
+    data,
+  });
+}
+export function applyreal(data) {
+  return ajax({
+    url: "/orders/add-house",
+    method: "post",
+    data,
+  });
+}
 
 /**
  * 取消预约
@@ -92,17 +93,38 @@ export function applyrang(data) {
 }
 
 /**
- * 获取app用户信息
+ * 获取app用户
  * @returns {AjaxPromise}
  */
-export function getAPPUser(data) {
-  return ajax({
-    urlType: "M3BaseURL",
+export function getAPPUser(data, header) {
+  return requestOrther({
     url: "/seeyon/thirdpartyController.do",
     method: "GET",
+    header,
     data,
   });
 }
+/**
+ * 获取apptoken
+ * @returns {AjaxPromise}
+ */
+export function getAPPToken(urldata) {
+  return requestOrther({
+    url: "/seeyon/rest/token/" + urldata,
+    method: "GET",
+  });
+}
+/**
+ * 获取app登录人员信息
+ * @returns {AjaxPromise}
+ */
+export function getAPPUserDetail(data) {
+  return requestOrther({
+    url: "/seeyon/rest/orgMember",
+    method: "GET",
+    data
+  });
+}
 
 /**
  * 获取当前打烊规则

+ 1 - 1
src/utils/request.js

@@ -23,7 +23,7 @@ export default function (ori) {
     let method = ori.method.toUpperCase();
     if (method === "GET") url +=  getdata(ori.data || {});
     xhttp.open(method, url, true);
-    xhttp.setRequestHeader("Content-type", "application/json");
+    xhttp.setRequestHeader("Content-type", ori.header ? ori.header.contentType || 'application/json' : "application/json");
     method === "GET" ? xhttp.send() : xhttp.send(JSON.stringify(ori.data));
     xhttp.onreadystatechange = function () {
       if (this.readyState != 4) return;

+ 49 - 0
src/utils/requestOrther.js

@@ -0,0 +1,49 @@
+import config from "../config/index.js";
+import { Toast } from "vant";
+import "vant/lib/toast/style/index";
+
+function getdata(data) {
+  let text = "";
+  for (const key in data) {
+    text += key + "=" + data[key] + "&";
+  }
+  text ? (text = "?" + text) : "";
+  text = text.replace(/&$/, "");
+  return text;
+}
+
+export default function (ori) {
+  let baseurl = config.base[ori.urlType || "defaultURl"];
+  let url = baseurl + ori.url;
+  return new Promise((resolve, reject) => {
+    var xhttp;
+    if (window.XMLHttpRequest) xhttp = new XMLHttpRequest();
+    else if (window.ActiveXObject)
+      xhttp = new window.ActiveXObject("Microsoft.XMLHTTP");
+    let method = ori.method.toUpperCase();
+    if (method === "GET") url += getdata(ori.data || {});
+    xhttp.open(method, url, true);
+    xhttp.setRequestHeader(
+      "Content-type",
+      ori.header
+        ? ori.header.contentType || "application/json"
+        : "application/json"
+    );
+    console.log(localStorage.token)
+    localStorage.token && xhttp.setRequestHeader("token", localStorage.token) 
+    method === "GET" ? xhttp.send() : xhttp.send(JSON.stringify(ori.data));
+    xhttp.onreadystatechange = function () {
+      if (this.readyState != 4) return;
+      if (this.status != 200) return Toast("请求失败 " + this.status);
+      let data = {};
+      try {
+        data = this.responseText || "";
+        resolve(data);
+      } catch (err) {
+        Toast("请求失败");
+        console.error(err);
+        reject(err);
+      }
+    };
+  });
+}

+ 27 - 4
src/views/Appointment.vue

@@ -59,7 +59,13 @@ import "vant/lib/icon/style/index";
 import "vant/lib/dialog/style/index";
 import "vant/lib/sidebar-item/style/index";
 
-import { orderList, cancel } from "../api/index";
+import {
+  orderList,
+  cancel,
+  getAPPUser,
+  getAPPToken,
+  getAPPUserDetail,
+} from "../api/index";
 import { urlSearchData } from "../utils/tool";
 
 export default {
@@ -74,10 +80,25 @@ export default {
     };
   },
   mounted() {
-    this.phone = this.$route.query.phone || "";
     let search = urlSearchData();
-    console.log(search);
     document.title = "预定";
+    getAPPUser({
+      ticket: search.ticket,
+    }).then(r => {
+      getAPPToken("rest/63bada00-7d01-4acc-ab2b-df8061eeeb8f").then(res => {
+        const t = JSON.parse(res || "{}");
+        localStorage.token = t.id;
+        getAPPUserDetail(
+          {
+            loginName: r,
+          },
+          res.id
+        ).then(detail => {
+          console.log(detail);
+        });
+      });
+      this.phone = this.$route.query.phone || "";
+    });
     orderList({
       userPhone: this.phone,
     }).then(res => {
@@ -126,7 +147,9 @@ export default {
       });
     },
   },
-  beforeUnmount: function () {},
+  beforeUnmount: function () {
+    localStorage.token = "";
+  },
   components: {
     vanSidebar,
     vanCell,