Bladeren bron

加载首页+接口返回

weixin_52219567 3 weken geleden
bovenliggende
commit
a83c06c728
8 gewijzigde bestanden met toevoegingen van 52 en 191 verwijderingen
  1. 4 2
      .env.development
  2. 2 117
      src/App.vue
  3. 1 1
      src/app/api/diy.ts
  4. 2 41
      src/app/pages/index/index.vue
  5. 2 3
      src/hooks/useDiy.ts
  6. 1 0
      src/hooks/useShare.ts
  7. 8 5
      src/utils/request.ts
  8. 32 22
      vite.config.ts

+ 4 - 2
.env.development

@@ -1,7 +1,9 @@
 NODE_ENV = 'development'
 
 # api请求地址
-VITE_APP_BASE_URL=''
+VITE_APP_BASE_URL='https://one.yoe365.com/'
+# VITE_APP_BASE_URL='http://yp1.yingpaipay.com:9026/'
+# VITE_APP_BASE_URL='https://jingyang.xiaoluwebsite.xyz/'
 
 # 图片服务器地址
 VITE_IMG_DOMAIN=''
@@ -10,7 +12,7 @@ VITE_IMG_DOMAIN=''
 VITE_REQUEST_STORAGE_TOKEN_KEY='wapToken'
 
 # 请求时header中token的参数名
-VITE_REQUEST_HEADER_TOKEN_KEY='token'
+VITE_REQUEST_HEADER_TOKEN_KEY='Authorization'
 
 # 请求时header中来源场景的参数名
 VITE_REQUEST_HEADER_CHANNEL_KEY='channel'

+ 2 - 117
src/App.vue

@@ -62,8 +62,8 @@ onLaunch((data: any) => {
 
     }
 
-    const { wechatInit } = useShare()
-    wechatInit()
+    // const { wechatInit } = useShare()
+    // wechatInit()
     // #endif
 
     // #ifdef MP
@@ -90,121 +90,6 @@ onLaunch((data: any) => {
     });
     // #endif
 
-    // 获取初始化数据信息
-    useSystemStore().getInitFn(async () => {
-
-        const configStore = useConfigStore()
-
-        let loginConfig = uni.getStorageSync('login_config')
-        if (!loginConfig) {
-            loginConfig = deepClone(configStore.login)
-        }
-
-        let url: any = currRoute()
-        // 设置主色调
-        setThemeColor(url)
-
-        // 判断账号锁定后在登录注册页面不进行请求三方登录注册,防止在页面出不去 member_lock 为账号锁定标识
-        if (uni.getStorageSync('member_lock') && (['app/pages/auth/index', 'app/pages/auth/login', 'app/pages/auth/register', 'app/pages/auth/resetpwd'].indexOf(url) != -1) && (loginConfig.is_username || loginConfig.is_mobile || loginConfig.is_bind_mobile)) {
-            return false
-        }
-
-        // 判断是否已登录
-        if (getToken()) {
-            const memberStore: any = useMemberStore()
-
-            await memberStore.setToken(getToken(), () => {
-                if (!uni.getStorageSync('openid')) {
-                    const memberInfo = useMemberStore().info
-                    const login = useLogin()
-
-                    // #ifdef MP-WEIXIN
-                    if (memberInfo.mobile) uni.setStorageSync('wap_member_mobile', memberInfo.mobile) // 存储会员手机号,防止重复请求微信获取手机号接口
-                    if (memberInfo && memberInfo.weapp_openid) {
-                        uni.setStorageSync('openid', memberInfo.weapp_openid) // 授权登录后存储openid
-                    } else {
-                        login.getAuthCode({ updateFlag: true }) // 更新openid
-                    }
-                    // #endif
-
-                    // #ifdef H5
-                    if (isWeixinBrowser()) {
-                        if (memberInfo && memberInfo.wx_openid) {
-                            uni.setStorageSync('openid', memberInfo.wx_openid)
-                        } else {
-                            if (data.query.code) {
-                                // 检测身份是否合法(当前登录的账号是不是我的),openid有效后才能更新登录
-                                login.updateOpenid(data.query.code, () => {
-                                    login.authLogin({ code: data.query.code })
-                                })
-                            } else if (loginConfig.is_auth_register && loginConfig.is_force_access_user_info) {
-                                // 强制获取用户信息
-                                login.getAuthCode({ scopes: 'snsapi_userinfo' })
-                            } else {
-                                // 静默获取
-                                login.getAuthCode({ scopes: 'snsapi_base' })
-                            }
-                        }
-                    }
-                    // #endif
-
-                }
-
-                // todo 已注册的会员不受影响
-                // 开启强制绑定手机号
-                if (uni.getStorageSync('isBindMobile')) {
-                    uni.removeStorageSync('isBindMobile');
-                }
-                //
-                // if (loginConfig.is_bind_mobile && !memberStore.info.mobile) {
-                //     // 强制绑定手机号
-                //     uni.setStorageSync('isBindMobile', true)
-                // }
-            })
-
-        }
-
-        if (!getToken()) {
-
-            // #ifdef MP
-            // 小程序 会员退出后不会自动登录
-            if (uni.getStorageSync('autoLoginLock')) return;
-            // #endif
-
-            const login = useLogin()
-
-            // #ifdef MP
-            // 第三方平台自动注册登录
-            login.getAuthCode()
-            // #endif
-
-            // #ifdef H5
-            if (isWeixinBrowser()) {
-                if (uni.getStorageSync('autoLoginLock') && !uni.getStorageSync('wechat_login_back')) return;
-                if (uni.getStorageSync('wechat_login_back')) {
-                    uni.removeStorageSync('wechat_login_back') // 删除微信公众号手动授权登录回调标识
-                    if (data.query.code) {
-                        login.authLogin({ code: data.query.code })
-                    }
-                } else if (loginConfig.is_auth_register && loginConfig.is_force_access_user_info) {
-                    // 开启自动注册会员,并且强制获取用户信息
-                    // 检测是否已授权获取用户信息
-                    // let nickname = uni.getStorageSync('nickname');
-                    // let avatar = uni.getStorageSync('avatar');
-                    // let openid = uni.getStorageSync('openid');
-                    // if (!nickname || !avatar || !openid) {}
-                    login.getAuthCode({ scopes: 'snsapi_userinfo' })
-                } else {
-                    // 检测是否已授权获取用户信息
-                    // let openid = uni.getStorageSync('openid');
-                    // if (!openid) {}
-                    login.getAuthCode({ scopes: 'snsapi_base' }) // 静默获取
-                }
-            }
-            // #endif
-        }
-    })
-
     // 控制弹窗展示
     uni.setStorageSync('isOnLoad', true); // 存储是页面是否加载完成的状态
 })

+ 1 - 1
src/app/api/diy.ts

@@ -4,7 +4,7 @@ import request from '@/utils/request'
  * 获取自定义页面信息
  */
 export function getDiyInfo(params: Record<string, any>) {
-    return request.get('diy/diy', params)
+    return request.get('mall/miniDiyPcPage/getMiniDiyPage', params)
 }
 
 /**

+ 2 - 41
src/app/pages/index/index.vue

@@ -1,8 +1,6 @@
 <template>
     <view :style="themeColor()">
-
         <loading-page :loading="diy.getLoading()"></loading-page>
-
         <view v-show="!diy.getLoading()">
 
             <!-- 自定义模板渲染 -->
@@ -14,58 +12,21 @@
 
         </view>
 
-        <!-- #ifdef MP-WEIXIN -->
-        <collect-tip ref="collectTipRef" ></collect-tip>
-        <!-- 小程序隐私协议 -->
-        <wx-privacy-popup ref="wxPrivacyPopupRef"></wx-privacy-popup>
-        <!-- #endif -->
-
     </view>
 </template>
 
 <script setup lang="ts">
-import { ref, nextTick } from 'vue';
 import { useDiy } from '@/hooks/useDiy'
-import { redirect } from '@/utils/common';
-import { useShare } from '@/hooks/useShare'
 import diyGroup from '@/addon/components/diy/group/index.vue'
-
-const { setShare } = useShare()
-
 uni.hideTabBar() // 隐藏tabbar
-
 const diy = useDiy({
-    name: 'DIY_INDEX'
+    type: '1'
 })
-
-const diyGroupRef = ref(null)
-
-const wxPrivacyPopupRef: any = ref(null)
-const collectTipRef: any = ref(null)
 // 监听页面加载
 diy.onLoad();
 
 // 监听页面显示
-diy.onShow((data: any) => {
-    if (data.value) {
-        // uni.setNavigationBarTitle({
-        // 	title: diyData.title
-        // })
-    } else if (data.page) {
-        // 跳转到设置的启动页
-        redirect({ url: data.page, mode: 'reLaunch' })
-    }
-    let share = data.share ? JSON.parse(data.share) : null;
-    setShare(share);
-    diyGroupRef.value?.refresh();
-
-    // #ifdef MP
-    nextTick(() => {
-        if (wxPrivacyPopupRef.value) wxPrivacyPopupRef.value.proactive();
-        if (collectTipRef.value) collectTipRef.value.show();
-    })
-    // #endif
-});
+diy.onShow((data: any) => {});
 
 // 监听页面隐藏
 diy.onHide();

+ 2 - 3
src/hooks/useDiy.ts

@@ -11,6 +11,7 @@ export function useDiy(params: any = {}) {
 
     const id = ref(0)
     const name = ref(params.name || '')
+    const type = ref(params.type || '')
     const template = ref('')
     const currRoute = ref('') //当前路由
     const requestData: any = reactive({});
@@ -103,9 +104,7 @@ export function useDiy(params: any = {}) {
                 diyStore.init();
             } else {
                 getDiyInfo({
-                    id: id.value,
-                    name: name.value,
-                    template: template.value
+                    type: type.value
                 }).then((res: any) => {
                     Object.assign(requestData, res.data);
                     if (requestData.value) {

+ 1 - 0
src/hooks/useShare.ts

@@ -42,6 +42,7 @@ export const useShare = () => {
     }
 
     const setShare = (options: any = {}) => {
+        return
         if (currRoute() == '' || currRoute().indexOf('app/pages/index/close') != -1 || currRoute().indexOf('app/pages/index/nosite') != -1) return;
 
         let queryStr = getQuery();

+ 8 - 5
src/utils/request.ts

@@ -21,7 +21,7 @@ class Request {
 
     constructor() {
         // #ifdef H5
-        this.baseUrl = import.meta.env.VITE_APP_BASE_URL || `${ location.origin }/api/`
+        this.baseUrl = '/dev-api/'
         // #endif
         // #ifndef H5
         this.baseUrl = import.meta.env.VITE_APP_BASE_URL
@@ -41,8 +41,9 @@ class Request {
     private requestInterceptors() {
         // 携带token
         try {
-            getToken() && (this.config.header[import.meta.env.VITE_REQUEST_HEADER_TOKEN_KEY] = getToken())
+            getToken() && (this.config.header[import.meta.env.VITE_REQUEST_HEADER_TOKEN_KEY] = 'Bearer '+ getToken())
             this.config.header[import.meta.env.VITE_REQUEST_HEADER_CHANNEL_KEY] = getAppChannel()
+            this.config.header.clientId = 'e5cd7e4891bf95d1d19206ce24a7b32e'
         } catch (e) {
         }
     }
@@ -105,6 +106,7 @@ class Request {
 
         const params = Object.assign(uni.$u.deepClone(this.config), config, {
             url: this.baseUrl + url,
+            // url:'/dev-api/'+ url,
             method
         })
 
@@ -116,14 +118,15 @@ class Request {
 
         return new Promise((resolve, reject) => {
             uni.request({
+                withCredentials:true,
                 ...params,
                 success: res => {
                     const data = res.data
-                    if (data.code == 1) {
+                    if (data.code == 200) {
                         config.showSuccessMessage && uni.showToast({ title: data.msg, icon: 'none' })
                         resolve(data)
                     } else {
-                        if (data.code == 0 || data.code == 400) {
+                        if (data.code == 0 || data.code == 500) {
                             if (config.showErrorMessage !== false) uni.showToast({ title: data.msg, icon: 'none' })
                         } else {
                             this.handleAuthError(data.code)
@@ -135,7 +138,7 @@ class Request {
                     reject(res)
                 },
                 complete: (res) => {
-                    this.handleRequestFail(res)
+                    // this.handleRequestFail(res)
                 }
             })
         })

+ 32 - 22
vite.config.ts

@@ -1,28 +1,38 @@
-import {defineConfig} from 'vite'
-import uni from '@dcloudio/vite-plugin-uni'
-import WindiCSS from 'vite-plugin-windicss'
-import MiniProgramTailwind from '@dcasia/mini-program-tailwind-webpack-plugin/rollup'
+import { defineConfig } from "vite";
+import uni from "@dcloudio/vite-plugin-uni";
+import WindiCSS from "vite-plugin-windicss";
+import MiniProgramTailwind from "@dcasia/mini-program-tailwind-webpack-plugin/rollup";
 
 const plugins = [
-    uni(),
-    WindiCSS({
-        scan: {
-            dirs: ['.'], // 当前目录下所有文件
-            fileExtensions: ['vue', 'js', 'ts'] // 同时启用扫描vue/js/ts
-        }
-    })
-]
+  uni(),
+  WindiCSS({
+    scan: {
+      dirs: ["."], // 当前目录下所有文件
+      fileExtensions: ["vue", "js", "ts"], // 同时启用扫描vue/js/ts
+    },
+  }),
+];
 
-process.env.UNI_PLATFORM == 'mp-weixin' && plugins.push(MiniProgramTailwind())
+process.env.UNI_PLATFORM == "mp-weixin" && plugins.push(MiniProgramTailwind());
 
 export default defineConfig({
-    server: {
-        host: '0.0.0.0',
-        // port: 6666,
-        // open:true // vite项目启动时自动打开浏览器
+  server: {
+    host: "0.0.0.0",
+    proxy: {
+      "/dev-api": {
+		  target: 'https://one.yoe365.com',
+        // target: "http://yp1.yingpaipay.com:9026",
+		// target: "https://jingyang.xiaoluwebsite.xyz",
+        changeOrigin: true,
+        secure: false,
+        rewrite: (path) => path.replace(new RegExp('^/dev-api'), '')
+      },
     },
-    plugins,
-    optimizeDeps: {
-        include: ['dayjs']
-    }
-})
+    // port: 6666,
+    // open:true // vite项目启动时自动打开浏览器
+  },
+  plugins,
+  optimizeDeps: {
+    include: ["dayjs"],
+  },
+});