From 9de6cf5226f7df076449a39c5adeb431b12fe923 Mon Sep 17 00:00:00 2001
From: wujingjing <gersonwu@qq.com>
Date: 星期一, 12 八月 2024 15:23:57 +0800
Subject: [PATCH] 页面可分享

---
 /dev/null                                          |   58 -----
 miniprogram/pages/my/my.ts                         |   33 +++
 miniprogram/config/constants.ts                    |    8 
 miniprogram/pages/login/login.ts                   |  336 ++++++++++++++++----------------
 miniprogram/utils/common.ts                        |    7 
 miniprogram/pages/scene/scene.wxml                 |    2 
 miniprogram/pages/knowledge-link/knowledge-link.ts |    6 
 miniprogram/pages/question/question.ts             |   47 ++--
 miniprogram/pages/scene/scene.ts                   |   54 +++++
 miniprogram/pages/web/web.ts                       |    9 
 10 files changed, 308 insertions(+), 252 deletions(-)

diff --git a/miniprogram/config/constants.ts b/miniprogram/config/constants.ts
index ab93b61..383d7a0 100644
--- a/miniprogram/config/constants.ts
+++ b/miniprogram/config/constants.ts
@@ -1 +1,7 @@
-export const STATIC_FILE_BASE_URL = 'https://wi.beng35.com';
\ No newline at end of file
+export const STATIC_FILE_BASE_URL = 'https://wi.beng35.com';
+
+export const SHARE_CONFIG = {
+  title: 'WI鏅鸿兘绠″',
+  path: "pages/login/login",
+  imageUrl: 'https://wi.beng35.com/static/images/logo/miniprogram-logo.png'
+}
\ No newline at end of file
diff --git a/miniprogram/pages/knowledge-link/knowledge-link.ts b/miniprogram/pages/knowledge-link/knowledge-link.ts
index ec5d4fe..fc6d37c 100644
--- a/miniprogram/pages/knowledge-link/knowledge-link.ts
+++ b/miniprogram/pages/knowledge-link/knowledge-link.ts
@@ -1,3 +1,5 @@
+import { SHARE_CONFIG } from "@/config/constants";
+
 // pages/knowledge-link/knowledge-link.ts
 Page({
 
@@ -68,6 +70,8 @@
    * 鐢ㄦ埛鐐瑰嚮鍙充笂瑙掑垎浜�
    */
   onShareAppMessage() {
-
+    return wx.$_.defaults(SHARE_CONFIG, {
+      // path: getCurrentUrl(),
+    })
   }
 })
\ No newline at end of file
diff --git a/miniprogram/pages/login/login.ts b/miniprogram/pages/login/login.ts
index 7413cf5..148f7b9 100644
--- a/miniprogram/pages/login/login.ts
+++ b/miniprogram/pages/login/login.ts
@@ -11,17 +11,18 @@
 // 瀵煎叆 store 瀵硅薄
 import { accountStore } from '@/stores/accountStore'
 
-import { STATIC_FILE_BASE_URL } from '@/config/constants'
+import { SHARE_CONFIG, STATIC_FILE_BASE_URL } from '@/config/constants'
 import { verifyPhone } from '@/utils/toolsValidate';
+import { getCurrentUrl } from '@/utils/common';
 const app = getApp();
 // 浣跨敤 ComponentWithStore 鏂规硶鏇挎崲 Component 鏂规硶鏋勯�犻〉闈�
-ComponentWithStore({
+Page({
   // 璁╅〉闈㈠拰 Store 瀵硅薄寤虹珛鍏宠仈
-  storeBindings: {
-    store: accountStore,
-    fields: ['session', 'username'],
-    actions: ['setSession', 'setUsername']
-  },
+  // storeBindings: {
+  //   store: accountStore,
+  //   fields: ['session', 'username'],
+  //   actions: ['setSession', 'setUsername']
+  // },
   data: {
     activeTab: 'account',
     user: '',
@@ -32,183 +33,184 @@
     phoneNumber: '',
     verifyCode: '',
   },
-  lifetimes: {
-    attached() {
-      wx.hideHomeButton();
-    },
+  onLoad() {
+    wx.hideHomeButton();
+  },
+  onHide() {
+    this.resetContent();
 
   },
-  pageLifetimes: {
-    hide() {
-      this.resetContent();
+
+
+  resetContent() {
+    switch (this.data.activeTab) {
+      case 'account':
+        this.setData({
+          user: '',
+          password: '',
+        })
+        break;
+      case 'cellPhoneNumber':
+        this.setData({
+          phoneNumber: '',
+          verifyCode: '',
+        })
+        this.stopCount();
+        this.setData({
+          countNum: null
+        })
+      default:
+        break;
     }
+
   },
-  methods: {
+  tabChange: function (event) {
+    this.setData({
+      activeTab: event.detail.name
+    })
+    this.resetContent();
+  },
+  async getSMSClick() {
+    if (this.data.countNum !== null) {
+      return;
+    }
+    if (!this.data.phoneNumber) {
+      toast({
+        title: '璇疯緭鍏ユ墜鏈哄彿鐮侊紒'
+      });
+      return;
+    }
+    const isValid = verifyPhone(this.data.phoneNumber)
+    console.log(isValid);
 
-    resetContent() {
-      switch (this.data.activeTab) {
-        case 'account':
-          this.setData({
-            user: '',
-            password: '',
-          })
-          break;
-        case 'cellPhoneNumber':
-          this.setData({
-            phoneNumber: '',
-            verifyCode: '',
-          })
-          this.stopCount();
-          this.setData({
-            countNum: null
-          })
-        default:
-          break;
-      }
+    if (!isValid) {
+      toast({
+        title: '璇疯緭鍏ユ纭殑鎵嬫満鍙风爜锛�'
+      });
+      return;
+    }
+    this.setData({
+      verifyCode: ''
+    })
+    const res = await loginVerifyMessage({
+      phone: this.data.phoneNumber
+    }, {
+      noAuth: true
+    })
 
-    },
-    tabChange: function (event) {
-      this.setData({
-        activeTab: event.detail.name
-      })
-      this.resetContent();
-    },
-    async getSMSClick() {
-      if (this.data.countNum !== null) {
-        return;
-      }
-      if (!this.data.phoneNumber) {
-        toast({
-          title: '璇疯緭鍏ユ墜鏈哄彿鐮侊紒'
-        });
-        return;
-      }
-      const isValid = verifyPhone(this.data.phoneNumber)
-      console.log(isValid);
-      
-      if (!isValid) {
-        toast({
-          title: '璇疯緭鍏ユ纭殑鎵嬫満鍙风爜锛�'
-        });
+    if (!res?.json_ok) {
+      return;
+    }
+    this.startCount();
+  },
+  stopCount() {
+    clearInterval(this.data.countTimer)
+  },
+
+  startCount() {
+    this.stopCount();
+    this.setData({
+      countNum: 60
+    })
+    this.data.countTimer = setInterval(() => {
+      if (this.data.countNum === 0) {
+        this.setData({
+          countNum: null
+        })
+        clearInterval(this.data.countTimer);
         return;
       }
       this.setData({
-        verifyCode: ''
+        countNum: this.data.countNum - 1
       })
-      const res = await loginVerifyMessage({
-        phone: this.data.phoneNumber
-      },{
-        noAuth: true
-      })
-      
-      if (!res?.json_ok) {
-        return;
-      }
-      this.startCount();
-    },
-    stopCount() {
-      clearInterval(this.data.countTimer)
-    },
+    }, 1000);
+  },
 
-    startCount() {
-      this.stopCount();
-      this.setData({
-        countNum: 60
-      })
-      this.data.countTimer = setInterval(() => {
-        if (this.data.countNum === 0) {
-          this.setData({
-            countNum: null
-          })
-          clearInterval(this.data.countTimer);
+  handlePhoneNumName(phoneStr) {
+    return phoneStr.substr(0, 3) + "****" + phoneStr.substr(7);
+  },
+
+  // 鎺堟潈鐧诲綍
+  login: wx.$_.debounce(async function () {
+
+    let res: any = null;
+    switch (this.data.activeTab) {
+      case 'account':
+        if (!this.data.user) {
+          toast({
+            title: '璇疯緭鍏ヨ处鍙凤紒'
+          });
           return;
         }
-        this.setData({
-          countNum: this.data.countNum - 1
-        })
-      }, 1000);
-    },
-
-    handlePhoneNumName(phoneStr){
-     return phoneStr.substr(0,3)+"****"+phoneStr.substr(7);
-    },
-
-    // 鎺堟潈鐧诲綍
-    login: wx.$_.debounce(async function () {
-
-      let res: any = null;
-      switch (this.data.activeTab) {
-        case 'account':
-          if (!this.data.user) {
-            toast({
-              title: '璇疯緭鍏ヨ处鍙凤紒'
-            });
-            return;
-          }
-          if (!this.data.password) {
-            toast({
-              title: '璇疯緭鍏ュ瘑鐮侊紒'
-            });
-            return;
-          }
-
-          res = await PostLogin({
-            user: this.data.user,
-            pass: this.data.password,
-          }, {
-            noAuth: true
+        if (!this.data.password) {
+          toast({
+            title: '璇疯緭鍏ュ瘑鐮侊紒'
           });
-          setStorage('username', this.data.user);
-          this.setUsername(this.data.user);
-          app.globalData.user.phoneNum = '';
+          return;
+        }
 
-          break;
-        case 'cellPhoneNumber':
+        res = await PostLogin({
+          user: this.data.user,
+          pass: this.data.password,
+        }, {
+          noAuth: true
+        });
+        setStorage('username', this.data.user);
+        // this.setUsername(this.data.user);
+        app.globalData.user.phoneNum = '';
 
-          if (!this.data.phoneNumber) {
-            toast({
-              title: '璇疯緭鍏ユ墜鏈哄彿鐮侊紒'
-            });
-            return;
-          }
-          if (!verifyPhone(this.data.phoneNumber)) {
-            toast({
-              title: '璇疯緭鍏ユ纭殑鎵嬫満鍙风爜锛�'
-            });
-            return;
-          }
-          if (!this.data.verifyCode) {
-            toast({
-              title: '璇疯緭鍏ラ獙璇佺爜锛�'
-            });
-            return;
-          }
-          res = await loginMessageUser({
-            phone: this.data.phoneNumber,
-            code: this.data.verifyCode,
-          }, {
-            noAuth: true
+        break;
+      case 'cellPhoneNumber':
+
+        if (!this.data.phoneNumber) {
+          toast({
+            title: '璇疯緭鍏ユ墜鏈哄彿鐮侊紒'
           });
-          const phoneName = this.handlePhoneNumName(this.data.phoneNumber) 
-          setStorage('username',phoneName);
-          this.setUsername(phoneName);
-          app.globalData.user.phoneNum = this.data.phoneNumber;
-          break;
-        default:
-          break;
-      }
-      if (!res.json_ok || !res.hswatersession) {
-        toast({
-          title: res.json_msg
-        })
-        return;
-      }
-      setStorage('session', res.hswatersession);
-      this.setSession(res.hswatersession)
+          return;
+        }
+        if (!verifyPhone(this.data.phoneNumber)) {
+          toast({
+            title: '璇疯緭鍏ユ纭殑鎵嬫満鍙风爜锛�'
+          });
+          return;
+        }
+        if (!this.data.verifyCode) {
+          toast({
+            title: '璇疯緭鍏ラ獙璇佺爜锛�'
+          });
+          return;
+        }
+        res = await loginMessageUser({
+          phone: this.data.phoneNumber,
+          code: this.data.verifyCode,
+        }, {
+          noAuth: true
+        });
+        const phoneName = this.handlePhoneNumName(this.data.phoneNumber)
+        setStorage('username', phoneName);
+        // this.setUsername(phoneName);
+        app.globalData.user.phoneNum = this.data.phoneNumber;
+        break;
+      default:
+        break;
+    }
+    if (!res.json_ok || !res.hswatersession) {
+      toast({
+        title: res.json_msg
+      })
+      return;
+    }
+    setStorage('session', res.hswatersession);
+    // this.setSession(res.hswatersession)
 
-      wx.switchTab({
-        url: '/pages/question/question'
-      });
-    }, 500),
+    wx.switchTab({
+      url: '/pages/question/question'
+    });
+  }, 500),
+
+  onShareAppMessage() {
+    return wx.$_.defaults(SHARE_CONFIG, {
+      path: getCurrentUrl(),
+    })
   }
 })
diff --git a/miniprogram/pages/my/my.js b/miniprogram/pages/my/my.js
deleted file mode 100644
index c69171f..0000000
--- a/miniprogram/pages/my/my.js
+++ /dev/null
@@ -1,36 +0,0 @@
-import { clearStorage,getStorage } from "@/utils/storage"
-const app = getApp();
-// pages/my/my.ts
-Component({
-
-  /**
-   * 椤甸潰鐨勫垵濮嬫暟鎹�
-   */
-  data: {
-    userName:getStorage('username'),
-    phoneNumber: app.globalData.user.phoneNum
-  },
-  methods:{
-    logout(){
-      clearStorage();
-      wx.reLaunch({
-        url: '/pages/login/login',
-      })
-    }
-  },
-
-  pageLifetimes: {
-    show() {
-      this.setData({
-        userName:getStorage('username'),
-        phoneNumber:app.globalData.user.phoneNum
-      })
-      if (typeof this.getTabBar === 'function' &&
-        this.getTabBar()) {
-        this.getTabBar().setData({
-          selected: 2
-        })
-      }
-    }
-  }
-})
\ No newline at end of file
diff --git a/miniprogram/pages/my/my.ts b/miniprogram/pages/my/my.ts
new file mode 100644
index 0000000..9c4d567
--- /dev/null
+++ b/miniprogram/pages/my/my.ts
@@ -0,0 +1,33 @@
+import { SHARE_CONFIG } from "@/config/constants";
+import { getCurrentUrl } from "@/utils/common";
+import { clearStorage,getStorage } from "@/utils/storage"
+const app = getApp();
+// pages/my/my.ts
+Page({
+
+  /**
+   * 椤甸潰鐨勫垵濮嬫暟鎹�
+   */
+  data: {
+    userName:getStorage('username'),
+    phoneNumber: app.globalData.user.phoneNum
+  },
+  logout(){
+    clearStorage();
+    wx.reLaunch({
+      url: '/pages/login/login',
+    })
+  },
+  onShow(){
+    this.setData({
+      userName:getStorage('username'),
+      phoneNumber:app.globalData.user.phoneNum
+    })
+  },
+
+  onShareAppMessage() {
+    return wx.$_.defaults(SHARE_CONFIG, {
+      // path: getCurrentUrl(),
+    })
+  }
+})
\ No newline at end of file
diff --git a/miniprogram/pages/question/question.ts b/miniprogram/pages/question/question.ts
index 0ce82c3..81dd301 100644
--- a/miniprogram/pages/question/question.ts
+++ b/miniprogram/pages/question/question.ts
@@ -18,6 +18,8 @@
 import { ComponentWithComputed, } from "miniprogram-computed";
 import { uuid } from "@/utils/uuid";
 import { getStorage } from "@/utils/storage";
+import { getCurrentUrl } from "@/utils/common";
+import { SHARE_CONFIG } from "@/config/constants";
 
 const app = getApp();
 // pages/question/question.js
@@ -129,27 +131,27 @@
     displaySampleList: [],
     section_a_id: '',
     sample_id: '',
-    userName:getStorage('username'),
-    keyboardHeight:0,
+    userName: getStorage('username'),
+    keyboardHeight: 0,
 
   },
-  onClickClear(){
+  onClickClear() {
     console.log('clear');
-    
+
     this.setData({
-      sendText:''
+      sendText: ''
     })
   },
-  inputFocus(e){
-    if(e.detail.height>0){
+  inputFocus(e) {
+    if (e.detail.height > 0) {
       this.setData({
-        keyboardHeight:e.detail.height-55
+        keyboardHeight: e.detail.height - 55
       })
     }
   },
-  changeInputBlur(e){
+  changeInputBlur(e) {
     this.setData({
-      keyboardHeight:0
+      keyboardHeight: 0
     })
   },
   async getSampleList() {
@@ -392,7 +394,7 @@
     })
 
   },
-  async getHistoryDetail( ) {
+  async getHistoryDetail() {
 
     const res = await QueryHistoryDetail({
       history_group_id: this.data.activeChatRoom.id,
@@ -437,9 +439,9 @@
       i++;
     });
 
-      // 杩囨护涓簄ull鐨勭粨鏋�
+    // 杩囨护涓簄ull鐨勭粨鏋�
     this.setData({
-      chatHistory: this.data.chatHistory.filter(item=>!!item)
+      chatHistory: this.data.chatHistory.filter(item => !!item)
     })
     this.scrollToBottom()
 
@@ -510,13 +512,11 @@
     if (!isPassed) return;
     this.getHistoryGroupData();
     this.getSampleList();
-    wx.onKeyboardHeightChange((res)=>{
-      console.log('馃殌 ~ res',res);
-    })
+
   },
-  onShow(){
+  onShow() {
     this.setData({
-      userName:getStorage('username')
+      userName: getStorage('username')
     })
   },
 
@@ -528,12 +528,12 @@
     }
     this.setData(
       {
-        section_a_id:sectionAId
+        section_a_id: sectionAId
       }
     )
     if (!this.data.activeChatRoom.isInitial) {
       try {
-      
+
         await this.newChatRoomClick(false)
       } finally {
         wx.hideLoading();
@@ -546,8 +546,13 @@
     this.sendText();
     app.globalData.sectionAId = '';
     app.globalData.sectionB = null;
+  },
+  onShareAppMessage() {
+    return wx.$_.defaults(SHARE_CONFIG, {
+      // path: getCurrentUrl(),
+    })
   }
-  
+
 
   // pageLifetimes: {
   //   show() {
diff --git a/miniprogram/pages/scene/scene.js b/miniprogram/pages/scene/scene.js
deleted file mode 100644
index 5acf55e..0000000
--- a/miniprogram/pages/scene/scene.js
+++ /dev/null
@@ -1,58 +0,0 @@
-import { getSectionByAllList } from "@/api/chat";
-
-const app = getApp();
-// pages/scene.ts
-Component({
-
-  /**
-   * 椤甸潰鐨勫垵濮嬫暟鎹�
-   */
-  data: {
-    sectionList: [],
-    iconList: ['bengzhan1', 'sanweiditu', 'jiankong']
-  },
-  methods:{
-    sectionBClick(e){
-      const item = e.currentTarget.dataset.item;
-      console.log('this.data.sectionList',this.data.sectionList);
-      const foundA = this.data.sectionList.find(sectionItem=>sectionItem.childrenChunkList?.some(childrenItem=>childrenItem.some(subItem=>subItem.section_id===item.section_id)) );
-      if(!foundA ) return;
-      // 鍓嶄竴涓〉闈紶閫掑弬鏁�
-      const jumpUrl = '/pages/question/question';
-      wx.switchTab({
-        url: jumpUrl,
-      });
-      app.globalData.sectionAId = foundA.section_id;
-      app.globalData.sectionB = item;
-    }
-  },
-  lifetimes: {
-
-    async attached() {
-      const res = await getSectionByAllList();
-      if(!res?.json_ok)return;
-      this.setData({
-        sectionList: res?.sections?.map(item => {
-          item.childrenChunkList = wx.$_.chunk(item.children, 3);
-          Reflect.deleteProperty(item, 'children');
-          return item;
-        })
-      })
-    },
-
-    detached(){
-      app.globalData.sectionAId = '';
-    }
-  },
-  pageLifetimes: {
-    show() {
-
-      if (typeof this.getTabBar === 'function' &&
-        this.getTabBar()) {
-        this.getTabBar().setData({
-          selected: 1
-        })
-      }
-    }
-  }
-})
\ No newline at end of file
diff --git a/miniprogram/pages/scene/scene.ts b/miniprogram/pages/scene/scene.ts
new file mode 100644
index 0000000..27a63cb
--- /dev/null
+++ b/miniprogram/pages/scene/scene.ts
@@ -0,0 +1,54 @@
+import {
+  getSectionByAllList
+} from "@/api/chat";
+import {
+  getCurrentUrl
+} from "@/utils/common";
+import {
+  SHARE_CONFIG
+} from "@/config/constants";
+const app = getApp();
+Page({
+
+  /**
+   * 椤甸潰鐨勫垵濮嬫暟鎹�
+   */
+  data: {
+    sectionList: [],
+    iconList: ['bengzhan1', 'sanweiditu', 'jiankong']
+  },
+  sectionBClick(e) {
+    const item = e.currentTarget.dataset.item;
+    console.log('this.data.sectionList', this.data.sectionList);
+    const foundA = this.data.sectionList.find(sectionItem => sectionItem.childrenChunkList?.some(childrenItem => childrenItem.some(subItem => subItem.section_id === item.section_id)));
+    if (!foundA) return;
+    // 鍓嶄竴涓〉闈紶閫掑弬鏁�
+    const jumpUrl = '/pages/question/question';
+    wx.switchTab({
+      url: jumpUrl,
+    });
+    app.globalData.sectionAId = foundA.section_id;
+    app.globalData.sectionB = item;
+  },
+  async onLoad() {
+    const res = await getSectionByAllList();
+    if (!res?.json_ok) return;
+    this.setData({
+      sectionList: res?.sections?.map(item => {
+        item.childrenChunkList = wx.$_.chunk(item.children, 3);
+        Reflect.deleteProperty(item, 'children');
+        return item;
+      })
+    })
+  },
+  onUnload() {
+    app.globalData.sectionAId = '';
+
+  },
+  onShareAppMessage() {
+    return wx.$_.defaults(SHARE_CONFIG, {
+      // path: getCurrentUrl(),
+    })
+  }
+
+})
\ No newline at end of file
diff --git a/miniprogram/pages/scene/scene.wxml b/miniprogram/pages/scene/scene.wxml
index 8316635..ca46ea0 100644
--- a/miniprogram/pages/scene/scene.wxml
+++ b/miniprogram/pages/scene/scene.wxml
@@ -1,4 +1,3 @@
-<!--pages/scene.wxml-->
 <view class="p-10 h-full ">
   <view class="flex flex-col h-full overflow-y-auto">
     <block wx:for="{{sectionList}}" wx:key="section_id">
@@ -7,7 +6,6 @@
         <view class="flex {{index===0 ? 'mt-0':'mt-15'}} ">
           <view class="size-210 flex flex-col p-10 rounded {{index===0 ? 'ml-0':'ml-15'}}" style="border: 1px solid rgb(212, 212, 212);" wx:for="{{item}}" wx:key="section_id" data-item="{{item}}" bind:tap="sectionBClick">
             <text class="ywicon icon-{{iconList[index]}} text-blue-600 font55"></text>
-            <!-- <image src="/assets/scene/scene_2.png"></image> -->
             <text class="font-bold font32 my-7">{{item.section_name}}</text>
             <text class="font26 overflow-hidden over-ellisis-3" style="-webkit-line-clamp: 3;">{{item.section_title}}</text>
           </view>
diff --git a/miniprogram/pages/web/web.ts b/miniprogram/pages/web/web.ts
index a9de0a9..0ae1cfb 100644
--- a/miniprogram/pages/web/web.ts
+++ b/miniprogram/pages/web/web.ts
@@ -1,3 +1,5 @@
+import { SHARE_CONFIG } from "@/config/constants";
+
 // pages/web/web.ts
 Page({
 
@@ -7,7 +9,7 @@
   data: {
     url: '',
   },
-  
+
   /**
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇
    */
@@ -66,7 +68,10 @@
   /**
    * 鐢ㄦ埛鐐瑰嚮鍙充笂瑙掑垎浜�
    */
-  onShareAppMessage() {
 
+  onShareAppMessage() {
+    return wx.$_.defaults(SHARE_CONFIG, {
+      // path: getCurrentUrl(),
+    })
   }
 })
\ No newline at end of file
diff --git a/miniprogram/utils/common.ts b/miniprogram/utils/common.ts
index 3d152db..9dfc9f7 100644
--- a/miniprogram/utils/common.ts
+++ b/miniprogram/utils/common.ts
@@ -24,3 +24,10 @@
 	return result;
 };
 
+export const getCurrentUrl = () =>{
+  const pages = getCurrentPages();
+
+  const currentPage = pages[pages.length - 1];
+  const url = `/${currentPage.route}`;
+  return url;
+}
\ No newline at end of file

--
Gitblit v1.9.3