huangziyang 2 долоо хоног өмнө
parent
commit
bdce17cfda

+ 12 - 0
App.vue

@@ -16,9 +16,21 @@ export default {
 </script>
 
 <style lang="scss">
+@import "@/uni.scss";
 /*每个页面公共css */
 @import "@/uni_modules/uni-scss/index.scss";
 /* #ifndef APP-NVUE */
 @import "@/static/customicons.css";
 /* #endif */
+button {
+  background-color: $primary;
+  font-weight: 500;
+  font-size: 32rpx;
+  color: #fff;
+  margin: 0;
+  width: 100%;
+  &::after {
+    border: 0;
+  }
+}
 </style>

+ 7 - 2
components/Container/Container.vue

@@ -1,4 +1,3 @@
-
 <script setup>
 import pages from "@/pages.json";
 import { ref, onMounted, watchEffect } from "vue";
@@ -75,9 +74,16 @@ onMounted(() => {
     ...systemInfo.safeArea,
     source: systemInfo.safeArea,
   };
+
+  // 解决部分安卓手机安全顶部为0 的bug
+  if (!safeArea.value.top) {
+    safeArea.value.top = systemInfo.statusBarHeight || 40;
+  }
+
   const isTarbarPage = pages.tabBar.list
     .map((item) => item.pagePath)
     .includes(getRoute().routeList[0].path);
+
   if (isTarbarPage) {
     // 高度再减掉tabbar高度
     safeArea.value.height -= 50;
@@ -181,7 +187,6 @@ defineExpose({
   </view>
 </template>
 
-
 <style lang="scss" scoped>
 @import "@/uni.scss";
 

+ 159 - 0
components/Modal/Modal.vue

@@ -0,0 +1,159 @@
+<script setup>
+import { ref, watchEffect, nextTick } from "vue";
+
+const popup = ref(null);
+
+const props = defineProps({
+  open: {
+    type: Boolean,
+    default: false,
+  },
+  backgroundColor: {
+    type: String,
+    default: "#fff",
+  },
+  width: {
+    type: String,
+    default: "600rpx",
+  },
+  height: {
+    type: String,
+    default: "",
+  },
+  title: {
+    type: String,
+    default: "",
+  },
+  footer: {
+    type: Boolean,
+    default: true,
+  },
+});
+const emit = defineEmits(["change", "close", "submit"]);
+
+const onChange = (e) => {
+  emit("change", e);
+};
+
+watchEffect(() => {
+  // 监听这两个函数
+  popup.value;
+  props.open;
+  nextTick(() => {
+    if (props.open) {
+      popup.value?.open?.();
+    } else {
+      popup.value?.close?.();
+    }
+  });
+});
+
+defineExpose({
+  popup,
+});
+</script>
+
+<template>
+  <uni-popup
+    ref="popup"
+    @change="onChange"
+    v-bind="$attrs"
+    background-color="transparent"
+  >
+    <view
+      class="popup-content"
+      :style="{
+        backgroundColor,
+        width,
+        height,
+      }"
+    >
+      <view class="title">
+        <slot name="title">{{ title }}</slot>
+        <uni-icons
+          type="closeempty"
+          class="icons"
+          @click="popup?.close"
+        ></uni-icons>
+      </view>
+      <view class="content">
+        <slot></slot>
+      </view>
+      <view v-if="footer" class="footer">
+        <slot name="footer">
+          <button class="plain" @click="emit('close')">取消</button>
+          <button class="primary" @click="emit('submit')">确认</button>
+        </slot>
+      </view>
+    </view>
+  </uni-popup>
+</template>
+
+<style scoped lang="scss">
+@import "@/uni.scss";
+
+.popup-content {
+  display: flex;
+  align-items: center;
+  flex-direction: column;
+  justify-content: space-between;
+  gap: 20rpx;
+  padding: 20rpx;
+  border-radius: 10rpx;
+
+  .title {
+    font-family: PingFang SC, PingFang SC;
+    font-weight: bold;
+    font-size: 36rpx;
+    color: #000000;
+    position: relative;
+    display: flex;
+    align-items: center;
+    justify-content: center;
+    width: 100%;
+    margin-top: 10rpx;
+
+    .icons {
+      position: absolute;
+      right: 0;
+      top: -10rpx;
+    }
+  }
+
+  .content {
+    width: 100%;
+    flex: 1;
+  }
+
+  .footer {
+    display: flex;
+    gap: 20rpx;
+    width: 100%;
+    padding: 0 30rpx;
+    box-sizing: border-box;
+
+    button {
+      flex: 1;
+      font-family: PingFang SC, PingFang SC;
+      border-radius: 100rpx 100rpx 100rpx 100rpx;
+      border: 1rpx solid $primary;
+      background-color: transparent;
+      font-weight: 500;
+      font-size: 32rpx;
+      &::after {
+        border: 0;
+      }
+    }
+
+    .plain {
+      background: $uni-primary-light;
+      color: $primary;
+    }
+
+    .primary {
+      background: $primary;
+      color: #fff;
+    }
+  }
+}
+</style>

+ 7 - 0
pages.json

@@ -35,6 +35,13 @@
         "navigationBarTitleText": "法规"
       }
     },
+    {
+      "path": "pages/order/index",
+      "style": {
+        "navigationStyle": "custom",
+        "navigationBarTitleText": "订单记录"
+      }
+    },
     {
       "path": "pages/recharge/index",
       "style": {

+ 30 - 16
pages/home/index.vue

@@ -42,19 +42,18 @@
               @clickItem="(e) => (current = e.currentIndex)"
             />
             <!-- 执业药师 -->
-            <view v-if="current === 0" class="grid">
-              <view v-for="item in 7" class="flex" @click="clickClass">
-                <view class="bg-red"></view>
-                <view> 执业药师{{ item }} </view>
+            <template v-for="(item, index) in list" :key="item.id">
+              <view v-if="current === index" class="grid">
+                <view
+                  v-for="item in list[0]?.children"
+                  class="flex"
+                  @click="clickClass"
+                >
+                  <view class="bg-red"></view>
+                  <view> {{ item.name }} </view>
+                </view>
               </view>
-            </view>
-            <!-- 药学职称 -->
-            <view v-if="current === 1" class="grid"
-              ><view v-for="item in 7" class="flex" @click="clickClass">
-                <view class="bg-red"></view>
-                <view> 药学职称{{ item }} </view>
-              </view></view
-            >
+            </template>
           </view>
         </uni-section>
       </view>
@@ -72,19 +71,34 @@
 </template>
 
 <script setup>
-import { ref } from "vue";
+import { ref, onMounted } from "vue";
 
 import Container from "../../components/Container/Container.vue";
 import { router } from "../../utils/router";
+import { request } from "../../utils/request";
+import { arrayToTree } from "../../utils";
 
 const current = ref(0);
 const items = ref(["标签1", "标签2"]);
+const list = ref([]);
 
 const clickClass = () => {
   router.push({
-    url: '/pages/regulations/index'
-  })
-}
+    url: "/pages/regulations/index",
+  });
+};
+
+onMounted(async () => {
+  const res = await request(
+    "api/question_bank/question_reception/chapter/get",
+    {},
+    "POST"
+  );
+  list.value = arrayToTree({
+    list: res.data,
+  });
+  items.value[0] = list.value[0].name;
+});
 </script>
 
 <style scoped lang="scss">

+ 79 - 45
pages/login/index.vue

@@ -1,34 +1,56 @@
 <template>
   <view>
     <view class="logo_box">
-      <image src="https://kailin-mp.oss-cn-shenzhen.aliyuncs.com/static/logo2.jpg" class="logo_image"></image>
+      <image
+        src="https://kailin-mp.oss-cn-shenzhen.aliyuncs.com/static/logo2.jpg"
+        class="logo_image"
+      ></image>
     </view>
     <view class="login_content">
       <!-- #ifdef MP-WEIXIN -->
-      <button open-type="getPhoneNumber" @getphonenumber="getPhonenumber" class="get_phone">授权登录</button>
+      <button
+        open-type="getPhoneNumber"
+        @getphonenumber="getPhonenumber"
+        class="get_phone"
+      >
+        授权登录
+      </button>
       <!-- #endif -->
       <!-- #ifdef H5 -->
       <button @click="toPhoneLogin" class="get_phone">授权登录</button>
       <!-- #endif -->
       <!-- #ifdef MP-TOUTIAO -->
-      <button open-type="getPhoneNumber" @getphonenumber="getPhonenumber" class="get_phone">抖音用户手机号授权登录</button>
+      <button
+        open-type="getPhoneNumber"
+        @getphonenumber="getPhonenumber"
+        class="get_phone"
+      >
+        抖音用户手机号授权登录
+      </button>
       <!-- <button class="get_phone" style="margin-top: 40rpx; background-color: #fff; color: #333">手机号验证登录</button> -->
       <!-- #endif -->
-      <button  class="cancel_login" @click="cancelLogin()">取消登录</button>
+      <button class="cancel_login" @click="cancelLogin()">取消登录</button>
       <view class="policy_content">
         <image
-            class="checkbox"
-            @click="changeAgreePolicy"
-            :src="agreePolicy ? 'https://kailin-mp.oss-cn-shenzhen.aliyuncs.com/static/icon/checked.png' : 'https://kailin-mp.oss-cn-shenzhen.aliyuncs.com/static/icon/checkbox.png'"
+          class="checkbox"
+          @click="changeAgreePolicy"
+          :src="
+            agreePolicy
+              ? 'https://kailin-mp.oss-cn-shenzhen.aliyuncs.com/static/icon/checked.png'
+              : 'https://kailin-mp.oss-cn-shenzhen.aliyuncs.com/static/icon/checkbox.png'
+          "
         ></image>
         我已阅读并同意
-        <navigator url="/pages/policy/index" style="color: #e03519">《服务协议》</navigator>
+        <navigator url="/pages/policy/index" style="color: #e03519"
+          >《服务协议》</navigator
+        >
       </view>
     </view>
   </view>
 </template>
 
 <script>
+import { router } from '../../utils/router';
 export default {
   data() {
     return {
@@ -47,7 +69,7 @@ export default {
     changeAgreePolicy() {
       this.agreePolicy = !this.agreePolicy;
     },
-    cancelLogin(){
+    cancelLogin() {
       // 返回上一页
       uni.navigateBack();
     },
@@ -64,55 +86,67 @@ export default {
       let share_uid = "";
       share_uid = uni.getStorageSync("share_uid");
       uni.login({
-        provider: 'weixin',
+        provider: "weixin",
         success: (loginRes) => {
           console.log(loginRes.code);
           // 登录成功,获取用户code
           let open_code = loginRes.code;
           // 授权成功以后,调用登录
-          this.$http.request("api/wechat/phone_number", { code: re.detail.code, share_uid: share_uid, open_code: open_code }, "post").then((re) => {
-            // 成功的话
-            if (re.code == "success") {
-              // 存储登录标识
-              uni.setStorageSync("userLogin", re.data);
-              if (!uni.getStorageSync("shopId")) {
-                uni.setStorageSync("shopId", re.data.shop_id);
+          this.$http
+            .request(
+              "api/wechat/phone_number",
+              {
+                code: re.detail.code,
+                share_uid: share_uid,
+                open_code: open_code,
+              },
+              "post"
+            )
+            .then((re) => {
+              // 成功的话
+              if (re.code == "success") {
+                // 存储登录标识
+                uni.setStorageSync("userLogin", re.data);
+                if (!uni.getStorageSync("shopId")) {
+                  uni.setStorageSync("shopId", re.data.shop_id);
+                }
+                // 跳转到页面
+                router.back()
+              } else {
+                uni.showToast({
+                  title: re.msg,
+                  icon: "none",
+                });
               }
-              // 跳转到页面
-				uni.switchTab({ url: "/pages/user/index" });
-            } else {
-              uni.showToast({
-                title: re.msg,
-                icon: "none",
-              });
-            }
-          });
+            });
         },
         fail: (err) => {
-          console.log('uni.login 接口调用失败,无法获取openid', err);
+          console.log("uni.login 接口调用失败,无法获取openid", err);
           uni.showToast({
-            title: '支付失败',
-            icon: 'none'
+            title: "支付失败",
+            icon: "none",
           });
-        }
+        },
       });
     },
     toPhoneLogin(re) {
       // 登录效果
-      this.$http.request("api/wechat/phone_number", this.requestParam).then((re) => {
-        // 成功的话
-        if (re.code == "success") {
-          // 存储登录标识
-          uni.setStorageSync("userLogin", re.data);
-          // 跳转到页面
-          uni.switchTab({ url: "/pages/user/index" });
-        } else {
-          uni.showToast({
-            title: re.msg,
-            icon: "none",
-          });
-        }
-      });
+      this.$http
+        .request("api/wechat/phone_number", this.requestParam)
+        .then((re) => {
+          // 成功的话
+          if (re.code == "success") {
+            // 存储登录标识
+            uni.setStorageSync("userLogin", re.data);
+            // 跳转到页面
+            uni.switchTab({ url: "/pages/user/index" });
+          } else {
+            uni.showToast({
+              title: re.msg,
+              icon: "none",
+            });
+          }
+        });
     },
   },
 };
@@ -159,7 +193,7 @@ export default {
 .get_phone::after {
   border: 0rpx solid #dddddd;
 }
-.cancel_login{
+.cancel_login {
   display: block;
   width: 100%;
   height: 80rpx;

+ 18 - 0
pages/order/index.vue

@@ -0,0 +1,18 @@
+<script setup name="order">
+import Container from "@/components/Container/Container.vue";
+import { request } from "@/utils/request";
+import { ref, onMounted } from "vue";
+
+const orderList = ref([]);
+
+onMounted(async () => {
+  const res = await request("api/question_bank/question_reception/orders/list");
+  console.log(res);
+});
+</script>
+
+<template>
+  <Container title="订单记录"> </Container>
+</template>
+
+<style scoped lang="scss"></style>

+ 25 - 10
pages/recharge/index.vue

@@ -126,22 +126,37 @@ const onSubmit = () => {
     success: async ({ code }) => {
       const package_id = data.value[activeCurrent.value]?.id;
       // 先调用新增订单再支付
-      // const order = await request('api/question_bank/question_reception/orders/add', {
-      //   package_id
-      // })
-      // console.log(order.data.order_id);
-      const { miniProgram } = uni.getAccountInfoSync();
-
-      const res = await request(
+      const order = await request(
+        "api/question_bank/question_reception/orders/add",
+        {
+          package_id,
+        }
+      );
+      const e = await request(
         "api/question_bank/question_reception/orders/wechat_pay",
         {
           code,
-          order_id: 3,
-          // app_id: miniProgram.appId,
+          order_id: order.data.order_id,
           app_id: ext.extAppid,
         }
       );
-      console.log(res);
+
+      console.log(e.data);
+
+      uni.requestPayment({
+        provider: "wxpay",
+        timeStamp: e.data.timeStamp, //时间戳
+        nonceStr: e.data.nonceStr, //随机字符串
+        package: e.data.package, //prepay_id
+        signType: e.data.signType, //签名算法MD5
+        paySign: e.data.paySign, //签名,
+        success(res) {
+          console.log(res);
+        },
+        fail(err) {
+          console.log(err);
+        },
+      });
     },
   });
 };

+ 37 - 2
pages/regulations/index.vue

@@ -9,6 +9,7 @@
       v-model="value"
       class="class-content"
       @change="onChnage"
+      v-show="showContainer"
     >
       <view class="free-content">
         <uni-collapse-item
@@ -59,12 +60,12 @@
         <view
           class="modal-mask"
           :style="{
-            height: `${maskStyle.height}px`,
+            height: `${-1}px`,
             width: `${maskStyle.width}px`,
           }"
         >
           <uni-icons type="locked" color="#fff" size="35"></uni-icons>
-          <view class="modal-wrapper">邀请好友可解锁</view>
+          <view class="modal-wrapper" @click="onClickMask">邀请好友可解锁</view>
         </view>
         <uni-collapse-item
           :title="`第${numberConvertToUppercase(index + 3)}章 ${item.title}`"
@@ -109,14 +110,31 @@
         </uni-collapse-item>
       </view>
     </uni-collapse>
+    <Modal
+      ref="popup"
+      background-color="#fff"
+      :open="!showContainer"
+      @change="onChange"
+      title="邀请新客户解锁课程"
+    >
+      <text class="unlock"
+        >邀请一名新用户注册并完成第一章全部考点学习,可解锁新两章内容</text
+      >
+      <template #footer>
+        <button>立即邀请</button>
+      </template>
+    </Modal>
   </Container>
 </template>
 
 <script setup name="regulations">
 import Container from "../../components/Container/Container.vue";
+import Modal from "@/components/Modal/Modal.vue";
 import { ref, getCurrentInstance } from "vue";
 import { numberConvertToUppercase, getRect } from "../../utils";
 const collapse = ref(null);
+const popup = ref(null);
+const showContainer = ref(true);
 const value = ref("");
 const instance = getCurrentInstance();
 const safeArea = ref({});
@@ -176,6 +194,14 @@ const onSafeAreaChange = (s) => {
 const onChnage = () => {
   resolveHeight();
 };
+
+const onChange = ({ show }) => {
+  showContainer.value = !show;
+};
+
+const onClickMask = () => {
+  showContainer.value = false;
+};
 </script>
 
 <style scoped lang="scss">
@@ -224,6 +250,15 @@ const onChnage = () => {
   }
 }
 
+.unlock {
+  font-family: PingFang SC, PingFang SC;
+  font-weight: 500;
+  font-size: 28rpx;
+  color: #000000;
+  margin: 100rpx 0;
+  display: block;
+}
+
 .class-content {
   height: 100%;
 }

+ 3 - 2
pages/user/index.vue

@@ -37,7 +37,7 @@
         <navigator class="navigator_item" url="/pages/recharge/index" v-else>
           <view class="navigator_title_vip">充值VIP中心banner入口</view>
         </navigator>
-        <navigator class="navigator_item" url="/pages/orders/index">
+        <navigator class="navigator_item" url="/pages/order/index">
           <view class="navigator_title">订单记录</view>
           <view class="navigator_title_ico"
             ><uni-icons type="right" size="20"></uni-icons
@@ -66,13 +66,14 @@
       </view>
     </view>
     <view class="service">
-      <view>联系客服</view>
+      <CustomerService>联系客服</CustomerService>
     </view>
   </Container>
 </template>
 
 <script>
 import Container from "../../components/Container/Container.vue";
+import CustomerService from "@/components/CustomerService/CustomerService.vue";
 
 export default {
   data() {

+ 34 - 1
utils/index.js

@@ -1,4 +1,3 @@
-import { getCurrentInstance } from "vue";
 // 获取元素宽高
 export const getRect = ({ name, onSuccess, instance, multiple }) => {
   // 创建一个选择器查询对象
@@ -53,3 +52,37 @@ export const numberConvertToUppercase = (num) => {
     }
   }
 };
+
+// 将扁平数组转为树形结构
+export const arrayToTree = ({
+  list,
+  id = "id",
+  pid = "parent_id",
+  firstId = 1,
+}) => {
+  let res = []; // 存放结果集
+  let map = {};
+  // 判断对象是否有某个属性
+  let getHasOwnProperty = (obj, property) =>
+    Object.prototype.hasOwnProperty.call(obj, property);
+
+  // 边做map存储,边找对应关系
+  for (const i of list) {
+    map[i[id]] = {
+      ...i,
+      children: getHasOwnProperty(map, i[id]) ? map[i[id]].children : [],
+    };
+    const newItem = map[i[id]];
+    if (i[pid] === firstId) {
+      res.push(newItem);
+    } else {
+      if (!getHasOwnProperty(map, i[pid])) {
+        map[i[pid]] = {
+          children: [],
+        };
+      }
+      map[i[pid]].children.push(newItem);
+    }
+  }
+  return res;
+};

+ 107 - 99
utils/request.js

@@ -1,115 +1,123 @@
-import ext from "./ext.js";
+import ext from "@/ext.json";
+import { router } from "./router";
 // 请求域名
-var domain = 'https://openwork.dfwy.tech/'
+var domain = "https://openwork.dfwy.tech/";
 //var domain = 'http://saas.com/'
 // #ifdef MP-WEIXIN
 // 'http://127.0.0.1:8000/';
 // domain = uni.getAccountInfoSync().miniProgram.envVersion == 'release' ? 'https://openwork.dfwy.tech/' : 'https://openwork.dfwy.tech/';
 // domain = uni.getAccountInfoSync().miniProgram.envVersion == 'release' ? ext.getExtStoreId('release_host_url') : ext.getExtStoreId('host_url');
-var app_id = ext.getExtStoreId('app_id') ? ext.getExtStoreId('app_id') : '';
+// var app_id = ext.getExtStoreId('app_id') ? ext.getExtStoreId('app_id') : '';
+var app_id = ext.extAppid;
 // #endif
 
 // 发送网络请求的函数
-export const request = (url, data = {}, method = 'GET') => {
-	// 获取登录标识
-	let userLogin = uni.getStorageSync('userLogin');
-	let shopId 	  = uni.getStorageSync("shopId");
-	// 合并参数
-	if( userLogin && userLogin.authcode ) data = Object.assign({authcode:userLogin.authcode},data);
-	if (shopId)	  data = Object.assign({shop_id:shopId},data);
-	if (app_id)	  data = Object.assign({app_id:app_id},data);
-	// 封装
-	return new Promise((resolve, reject) => {
-		uni.request({
-			url: domain+url,
-			method: method,
-			data: data,
-			success: (res) => {
-				// 登录提示
-				if(res.data.code == 'no_login'){
-					// 清空登录标识
-					uni.setStorageSync('userLogin',null);
-					// 清空用户信息
-					uni.setStorageSync('userInfo',null);
-					// 前去登录
-					uni.showModal({
-						title:"请登录",
-						success(res){
-							if (res.confirm) {
-								// 用户点击确定按钮
-								uni.navigateTo({
-									url:"/pages/login/index"
-								})
-							}
-						}
-					})
-				}
-				// 返回结果
-				resolve(res.data)
-			},
-			fail: (err) => {
-				reject(err)
-			}
-		})
-	})
-}
+export const request = (url, data = {}, method = "GET") => {
+  // 获取登录标识
+  let userLogin = uni.getStorageSync("userLogin");
+  let shopId = uni.getStorageSync("shopId");
+  // 合并参数
+  if (userLogin && userLogin.authcode)
+    data = Object.assign({ authcode: userLogin.authcode }, data);
+  if (shopId) data = Object.assign({ shop_id: shopId }, data);
+  if (app_id) data = Object.assign({ app_id: app_id }, data);
+  // 封装
+  return new Promise((resolve, reject) => {
+    uni.request({
+      url: domain + url,
+      method: method,
+      data: data,
+      success: (res) => {
+        // 登录提示
+        if (res.data.code == "no_login") {
+          // 清空登录标识
+          uni.setStorageSync("userLogin", null);
+          // 清空用户信息
+          uni.setStorageSync("userInfo", null);
+          // 前去登录
+          uni.showModal({
+            title: "请登录",
+            success(res) {
+              if (res.confirm) {
+                // 用户点击确定按钮
+                router.push({
+                  url: "/pages/login/index",
+                });
+              }
+            },
+          });
+          reject("请登录");
+        }
+        // 返回结果
+        resolve(res.data);
+      },
+      fail: (err) => {
+        reject(err);
+      },
+    });
+  });
+};
 
-const fileupload = (url, filePath,data = {}) =>{
-	// 获取登录标识
-	let userLogin = uni.getStorageSync('userLogin');
-	// 合并参数
-	if( userLogin && userLogin.authcode ) data = Object.assign({authcode:userLogin.authcode},data);
-	if (app_id)	  data = Object.assign({app_id:app_id},data);
-	// 封装
-	return new Promise((resolve, reject) => {
-		uni.uploadFile({
-			url: domain+url, // 你的上传接口地址
-			filePath: filePath,
-			name: 'file', // 必须填写,为了后端接收文件流的参数名字
-			formData: data,// 其他要上传的参数
-			success: (res) => {
-				// 登录提示
-				if(res.data.code == 'no_login'){
-					// 前去登录
-					uni.showModal({
-						title:"请登录",
-						success(res){
-							if (res.confirm) {
-								// 用户点击确定按钮
-								uni.navigateTo({
-									url:"/pages/login/index"
-								})
-							}
-						}
-					})
-				}
-				// 转json,php返回可能会带bom头需要先替换
-				let resdata = JSON.parse(res.data.replace('\uFEFF',''));
-				resolve(resdata)
-			},
-			fail: (err) => {
-				reject(err)
-			}
-		});
-	})
-}
+const fileupload = (url, filePath, data = {}) => {
+  // 获取登录标识
+  let userLogin = uni.getStorageSync("userLogin");
+  // 合并参数
+  if (userLogin && userLogin.authcode)
+    data = Object.assign({ authcode: userLogin.authcode }, data);
+  if (app_id) data = Object.assign({ app_id: app_id }, data);
+  // 封装
+  return new Promise((resolve, reject) => {
+    uni.uploadFile({
+      url: domain + url, // 你的上传接口地址
+      filePath: filePath,
+      name: "file", // 必须填写,为了后端接收文件流的参数名字
+      formData: data, // 其他要上传的参数
+      success: (res) => {
+        // 登录提示
+        if (res.data.code == "no_login") {
+          // 前去登录
+          uni.showModal({
+            title: "请登录",
+            success(res) {
+              if (res.confirm) {
+                // 用户点击确定按钮
+                uni.navigateTo({
+                  url: "/pages/login/index",
+                });
+              }
+            },
+          });
+        }
+        // 转json,php返回可能会带bom头需要先替换
+        let resdata = JSON.parse(res.data.replace("\uFEFF", ""));
+        resolve(resdata);
+      },
+      fail: (err) => {
+        reject(err);
+      },
+    });
+  });
+};
 
 // 字符串键值对转参数对象
-const strToParam = (str, separator = '&')=> {
-	// 先转码
-	str			= decodeURIComponent(str);
-	let pairs 	= str.split(separator);
-	let result 	= {};
-	pairs.forEach(pair => {
-		let [key, value] = pair.split('=');
-		result[key] = value;
-	});
-	// 返回结果
-	return result;
-}
-
+const strToParam = (str, separator = "&") => {
+  // 先转码
+  str = decodeURIComponent(str);
+  let pairs = str.split(separator);
+  let result = {};
+  pairs.forEach((pair) => {
+    let [key, value] = pair.split("=");
+    result[key] = value;
+  });
+  // 返回结果
+  return result;
+};
 
 // 模块导出,{name:object} 为对象式,导出多个使用
 // export default {request:request,request1:request1};
 // 单个对象,直接导出如下
-export default {request:request,fileupload:fileupload,strToParam:strToParam}
+export default {
+  request: request,
+  fileupload: fileupload,
+  strToParam: strToParam,
+};

+ 6 - 3
utils/router.js

@@ -34,7 +34,10 @@ const normalizeParams = (url, options) => {
   } else {
     normalizeOptions = url;
   }
-  const params = normalizeOptions.params || {};
+  const params = {
+    redirected: getRoute().routeList[0].path,
+    ...normalizeOptions.params
+  };
   normalizeOptions.url += objToUrlParams(params);
   delete normalizeOptions.params;
   return normalizeOptions;
@@ -82,7 +85,7 @@ export const router = {
     const { redirected, ...params } = route[0].params;
     if (redirected) {
       this.reLaunch({
-        url: redirected,
+        url: `/${redirected}`,
         params,
       });
     }
@@ -101,6 +104,6 @@ export const getRoute = () => {
   });
 
   return {
-    routeList,
+    routeList:routeList.reverse(),
   };
 };