瀏覽代碼

delete uview

nanMing 1 年之前
父節點
當前提交
b46872afee
共有 10 個文件被更改,包括 135 次插入201 次删除
  1. 23 13
      App.vue
  2. 0 37
      api/login.js
  3. 0 13
      common/auth.js
  4. 4 3
      common/request.js
  5. 8 8
      main.js
  6. 1 2
      package.json
  7. 55 69
      pages.json
  8. 2 2
      pages/index/index.vue
  9. 42 52
      pages/login/login.vue
  10. 0 2
      uni.scss

+ 23 - 13
App.vue

@@ -1,17 +1,27 @@
 <script>
 <script>
-	export default {
-		onLaunch: function() {
-			 // uni.hideTabBar()
-			console.log('App Launch')
-		},
-		onShow: function() {
-			console.log('App Show')
-		},
-		onHide: function() {
-			console.log('App Hide')
-		}
-	}
+  import { getToken } from '@/common/auth.js'
+  export default {
+    onLaunch: (options) => {
+      const openid = uni.getStorageSync('openid') || null
+      const token = getToken() || null
+      console.log(options);
+      if (!openid) {
+        console.log('no id');
+        uni.reLaunch({
+          url: '/pages/login/login'
+        })
+      }
+      // uni.hideTabBar()
+      console.log('App Launch')
+    },
+    onShow: () => {
+      console.log('App Show')
+    },
+    onHide: () => {
+      console.log('App Hide')
+    }
+  }
 </script>
 </script>
 
 
 <style>
 <style>
-</style>
+</style>

+ 0 - 37
api/login.js

@@ -1,14 +1,5 @@
 import request from '@/common/request.js'
 import request from '@/common/request.js'
 
 
-// 注册方法
-export function register(data) {
-	return request({
-		url: '/business/registration',
-		method: 'post',
-		data: data
-	})
-}
-
 // 登录方法
 // 登录方法
 export const login = (data) => {
 export const login = (data) => {
 	return request({
 	return request({
@@ -20,32 +11,4 @@ export const login = (data) => {
 		method: 'post',
 		method: 'post',
 		data: data
 		data: data
 	})
 	})
-}
-
-// 获取用户详细信息
-export function getInfo() {
-	return request({
-		url: '/getInfo',
-		method: 'get'
-	})
-}
-
-// 退出方法
-export function logout() {
-	return request({
-		url: '/logout',
-		method: 'post'
-	})
-}
-
-// 获取验证码
-export function getCodeImg() {
-	return request({
-		url: '/captchaImage',
-		headers: {
-			isToken: false
-		},
-		method: 'get',
-		timeout: 20000
-	})
 }
 }

+ 0 - 13
common/auth.js

@@ -1,5 +1,4 @@
 const TokenKey = 'App-Token'
 const TokenKey = 'App-Token'
-const wxId = 'openid'
 
 
 export function getToken() {
 export function getToken() {
   return uni.getStorageSync(TokenKey)
   return uni.getStorageSync(TokenKey)
@@ -11,16 +10,4 @@ export function setToken(token) {
 
 
 export function removeToken() {
 export function removeToken() {
   return uni.removeStorageSync(TokenKey)
   return uni.removeStorageSync(TokenKey)
-}
-
-export function getWxId() {
-  return uni.getStorageSync(wxId)
-}
-
-export function setWxId(openId) {
-  return uni.setStorageSync(wxId, openId)
-}
-
-export function removeWxId() {
-  return uni.removeStorageSync(wxId)
 }
 }

+ 4 - 3
common/request.js

@@ -8,10 +8,11 @@ const request = config => {
   config.header = config.header || {}
   config.header = config.header || {}
   if (getToken()) {
   if (getToken()) {
     config.header['Authorization'] = 'Bearer ' + getToken()
     config.header['Authorization'] = 'Bearer ' + getToken()
-  } else {
-    config.header['Authorization'] = 'Bearer ' +
-      'eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyX2lkIjo3MDA0NDMsInVzZXJfa2V5IjoiNjFlMDVkMWItODY1Zi00MGIwLThiOWItM2VjY2I0ZGEzYjAwIiwidXNlcm5hbWUiOiJ5bGpnMjIwMjgyMDAzMiJ9.K16sZmP0X54BsIt5dpPBm5Jw8VLoQR3Vt1VJ8IpdRNChDwZNthxfCBAKPkUAilFtb5NuBIppH54dktTPSV5mNA'
   }
   }
+  //  else {
+  //   config.header['Authorization'] = 'Bearer ' +
+  //     'eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyX2lkIjo3MDA0NDMsInVzZXJfa2V5IjoiNjFlMDVkMWItODY1Zi00MGIwLThiOWItM2VjY2I0ZGEzYjAwIiwidXNlcm5hbWUiOiJ5bGpnMjIwMjgyMDAzMiJ9.K16sZmP0X54BsIt5dpPBm5Jw8VLoQR3Vt1VJ8IpdRNChDwZNthxfCBAKPkUAilFtb5NuBIppH54dktTPSV5mNA'
+  // }
 
 
   uni.showLoading({
   uni.showLoading({
     title: '请求中...'
     title: '请求中...'

+ 8 - 8
main.js

@@ -1,8 +1,8 @@
-import uView from 'uview-ui'
-import "uview-ui/index.scss";
 import App from './App'
 import App from './App'
 
 
-Vue.use(uView)
+import { toast } from './common/common.js'
+
+Vue.prototype.toast = toast
 
 
 // #ifndef VUE3
 // #ifndef VUE3
 import Vue from 'vue'
 import Vue from 'vue'
@@ -10,7 +10,7 @@ import './uni.promisify.adaptor'
 Vue.config.productionTip = false
 Vue.config.productionTip = false
 App.mpType = 'app'
 App.mpType = 'app'
 const app = new Vue({
 const app = new Vue({
-	...App
+  ...App
 })
 })
 app.$mount()
 app.$mount()
 // #endif
 // #endif
@@ -18,9 +18,9 @@ app.$mount()
 // #ifdef VUE3
 // #ifdef VUE3
 import { createSSRApp } from 'vue'
 import { createSSRApp } from 'vue'
 export function createApp() {
 export function createApp() {
-	const app = createSSRApp(App)
-	return {
-		app
-	}
+  const app = createSSRApp(App)
+  return {
+    app
+  }
 }
 }
 // #endif
 // #endif

+ 1 - 2
package.json

@@ -4,7 +4,6 @@
 		"sass-loader": "^13.3.3"
 		"sass-loader": "^13.3.3"
 	},
 	},
 	"dependencies": {
 	"dependencies": {
-		"@dcloudio/uni-app": "^2.0.2-3090920231225001",
-		"uview-ui": "^2.0.36"
+		"@dcloudio/uni-app": "^2.0.2-3090920231225001"
 	}
 	}
 }
 }

+ 55 - 69
pages.json

@@ -1,79 +1,65 @@
 {
 {
-
-	"tabBar": {
-		"color": "#7A7E83",
-		"selectedColor": "#3cc51f",
-		"borderStyle": "black",
-		"backgroundColor": "#ffffff",
-		"list": [{
-				"pagePath": "pages/index/index",
-				"iconPath": "static/image/index.png",
-				"selectedIconPath": "static/image/index-s.png",
-				"text": "首页"
+  "lazyCodeLoading": "requiredComponents",
+  "tabBar": {
+    "color": "#7A7E83",
+    "selectedColor": "#3cc51f",
+    "borderStyle": "black",
+    "backgroundColor": "#ffffff",
+    "list": [{
+        "pagePath": "pages/index/index",
+        "iconPath": "static/image/index.png",
+        "selectedIconPath": "static/image/index-s.png",
+        "text": "首页"
 			},
 			},
-			{
-				"pagePath": "pages/my/index",
-				"iconPath": "static/image/my.png",
-				"selectedIconPath": "static/image/my-s.png",
-				"text": "我的"
+      {
+        "pagePath": "pages/my/index",
+        "iconPath": "static/image/my.png",
+        "selectedIconPath": "static/image/my-s.png",
+        "text": "我的"
 			}
 			}
 		]
 		]
-	},
-	
-	"easycom": {
-		"^u-(.*)": "uview-ui/components/u-$1/u-$1.vue"
-	},
-	
-	"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
-		{
-			"path": "pages/index/index",
-			"style": {
-				"navigationBarTitleText": "首页"
-			}
-		},
-		{
-			"path": "pages/login/login",
-			"style": {
-				"navigationBarTitleText": "",
-				"enablePullDownRefresh": false
-			}
+  },
+
+  "pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
+    {
+      "path": "pages/index/index",
+      "style": {
+        "navigationBarTitleText": "首页"
+      }
 		},
 		},
-		{
-			"path": "pages/my/index",
-			"style": {
-				"navigationBarTitleText": "个人中心",
-				"enablePullDownRefresh": true,
-				"onReachBottomDistance": 100 //距离底部100像素时,触发加载更多功能
-			}
+    {
+      "path": "pages/login/login",
+      "style": {
+        "navigationBarTitleText": "登录",
+        "enablePullDownRefresh": true
+      }
+    },
+    {
+      "path": "pages/my/index",
+      "style": {
+        "navigationBarTitleText": "个人中心",
+        "enablePullDownRefresh": true,
+        "onReachBottomDistance": 100 //距离底部100像素时,触发加载更多功能
+      }
 		},
 		},
-		{
-			"path": "pages/lr/index",
-			"style": {
-				"navigationBarTitleText": "添加客户信息"
-			}
+    {
+      "path": "pages/lr/index",
+      "style": {
+        "navigationBarTitleText": "添加客户信息"
+      }
 		},
 		},
-		{
-			"path": "pages/lr/bhAdd",
-			"style": {
-				"navigationBarTitleText": "添加病史记录"
-			}
+    {
+      "path": "pages/lr/bhAdd",
+      "style": {
+        "navigationBarTitleText": "添加病史记录"
+      }
 		}
 		}
 	],
 	],
-	"globalStyle": {
-		"navigationBarTextStyle": "black",
-		"navigationBarTitleText": "uni-app",
-		"navigationBarBackgroundColor": "#F8F8F8",
-		"backgroundColor": "#F8F8F8"
-	},
-	"uniIdRouter": {},
-	"condition" : { //模式配置,仅开发期间生效
-		"current": 0, //当前激活的模式(list 的索引项)
-		"list": [
-			{
-				"name": "login", //模式名称
-				"path": "pages/login/login", //启动页面,必选
-				"query": "" //启动参数,在页面的onLoad函数里面得到
-			}
-		]
-	}
+  "globalStyle": {
+    "navigationBarTextStyle": "black",
+    "navigationBarTitleText": "uni-app",
+    "navigationBarBackgroundColor": "#F8F8F8",
+    "backgroundColor": "#F8F8F8"
+  },
+  "uniIdRouter": {}
 }
 }

+ 2 - 2
pages/index/index.vue

@@ -1,6 +1,6 @@
 <template>
 <template>
 	<view class="page-main">
 	<view class="page-main">
-		<next-indexed-xlist :dataList="dataList" :showAvatar="true" isInterlock @itemclick="itemclick">
+		<!-- <next-indexed-xlist :dataList="dataList" :showAvatar="true" isInterlock @itemclick="itemclick"> -->
 			<!--这是默认插槽,额外添加部分-->
 			<!--这是默认插槽,额外添加部分-->
 			<!--    <view class="content-block">
 			<!--    <view class="content-block">
                 <view class="title"><text>历史记录:</text></view>
                 <view class="title"><text>历史记录:</text></view>
@@ -8,7 +8,7 @@
                 <view class="btn"><text>东城区</text></view>
                 <view class="btn"><text>东城区</text></view>
                 <view class="btn"><text>海淀区</text></view>
                 <view class="btn"><text>海淀区</text></view>
             </view> -->
             </view> -->
-		</next-indexed-xlist>
+		<!-- </next-indexed-xlist> -->
 		<navigator url="/pages/lr/index">
 		<navigator url="/pages/lr/index">
 			<image src="../../static/image/add.png" class="floating-button"></image>
 			<image src="../../static/image/add.png" class="floating-button"></image>
 		</navigator>
 		</navigator>

+ 42 - 52
pages/login/login.vue

@@ -1,39 +1,22 @@
 <template>
 <template>
-  <view class="u-page">
-    <u--form ref="loginForm" :model="form" :rules="rules" errorType="toast">
-      <u-row justify="center">
-        <u-col span="9">
-          <u-form-item prop="username">
-            <u-input v-model="form.username" type="number" placeholder="请输入手机号" prefixIcon="account"
-              :clearable="true" />
-          </u-form-item>
-        </u-col>
-      </u-row>
-
-      <u-row justify="center">
-        <u-col span="9">
-          <u-form-item prop="password">
-            <u-input v-model="form.password" type="password" placeholder="请输入密码" prefixIcon="lock" :clearable="true" />
-          </u-form-item>
-        </u-col>
-      </u-row>
-
-      <u-row justify="center">
-        <u-col span="9">
-          <u-form-item>
-            <u-button type="success" text="登录并绑定微信" @click="submitForm"></u-button>
-            <!-- <u-text type="info" align="center" text="微信一键登录" @click="quickLogin"></u-text> -->
-          </u-form-item>
-        </u-col>
-      </u-row>
-    </u--form>
+  <view class="login-page">
+    <uni-forms ref="loginForm" :model="form" :rules="rules">
+      <uni-forms-item name="username">
+        <uni-easyinput v-model="form.username" type="number" placeholder="请输入手机号" prefixIcon="account"
+          :clearable="true" />
+      </uni-forms-item>
 
 
+      <uni-forms-item name="password">
+        <uni-easyinput v-model="form.password" type="password" placeholder="请输入密码" prefixIcon="lock"
+          :clearable="true" />
+      </uni-forms-item>
+    </uni-forms>
+    <button type="primary" @click="submitForm">登录并绑定微信</button>
   </view>
   </view>
 </template>
 </template>
 
 
 <script>
 <script>
   import { setToken } from '@/common/auth.js'
   import { setToken } from '@/common/auth.js'
-  import { toast } from '@/common/common.js'
   import { login } from '@/api/login.js'
   import { login } from '@/api/login.js'
 
 
   export default {
   export default {
@@ -44,53 +27,60 @@
           password: 'sckj@2022',
           password: 'sckj@2022',
         },
         },
         rules: {
         rules: {
-          username: [
-            { required: true, message: '手机号不能为空', trigger: ['blur', 'change'] },
-            { len: 11, message: '手机号应为11位数字', trigger: ['blur', 'change'] },
-					],
-          password: [
-            { required: true, message: '密码不能为空', trigger: ['blur', 'change'] },
-            { min: 6, message: '密码长度应大于6位', trigger: ['blur', 'change'] },
-					]
+          username: {
+            rules: [
+              { required: true, errorMessage: '手机号不能为空' },
+              { format: 'number', errorMessage: '手机号应为数字' },
+            ]
+          },
+          password: {
+            rules: [
+              { required: true, errorMessage: '密码不能为空' },
+            ]
+          }
         },
         },
       }
       }
     },
     },
-    onReady() {
-      this.$refs.loginForm.setRules(this.rules)
-    },
-
     methods: {
     methods: {
       submitForm() {
       submitForm() {
         this.$refs.loginForm.validate().then(() => {
         this.$refs.loginForm.validate().then(() => {
-          uni.login({
+          // #ifdef MP-WEIXIN
+          uni.getUserInfo({ // 获取用户头像并存储
+            provider: 'weixin',
+            withCredentials: true,
+          }).then((userData) => {
+            uni.setStorageSync('avatar', userData.userInfo.avatarUrl)
+          })
+
+          uni.login({ // 获取用户登录凭证换取openid
             provider: 'weixin',
             provider: 'weixin',
             success: (loginRes) => {
             success: (loginRes) => {
-              console.log(loginRes);
               const params = {
               const params = {
                 ...this.form,
                 ...this.form,
                 code: loginRes.code,
                 code: loginRes.code,
               }
               }
-              console.log(params);
               login(params).then((res) => {
               login(params).then((res) => {
                 if (res.code === 200) {
                 if (res.code === 200) {
                   const { data } = res
                   const { data } = res
-                  setToken(data.access_token)
-                  // uni.reLaunch({ url: '/pages/index/index' })
+                  uni.setStorageSync('openid', data.openId)
+                  setToken(data.token.access_token)
+                  uni.reLaunch({ url: '/pages/index/index' })
                 } else {
                 } else {
-                  toast(res.msg)
+                  this.toast(res.msg)
                 }
                 }
               })
               })
             }
             }
           })
           })
-
+          // #endif
         }).catch(() => {})
         }).catch(() => {})
       },
       },
-      quickLogin() {
-        console.log('quick login');
-      }
     }
     }
   }
   }
 </script>
 </script>
 
 
-<style lang="scss">
+<style lang="scss" scoped>
+  .login-page {
+    width: 80%;
+    margin: 35% auto;
+  }
 </style>
 </style>

+ 0 - 2
uni.scss

@@ -12,8 +12,6 @@
  * 如果你的项目同样使用了scss预处理,你也可以直接在你的 scss 代码中使用如下变量,同时无需 import 这个文件
  * 如果你的项目同样使用了scss预处理,你也可以直接在你的 scss 代码中使用如下变量,同时无需 import 这个文件
  */
  */
 
 
-@import 'uview-ui/theme.scss';
-
 /* 颜色变量 */
 /* 颜色变量 */
 
 
 /* 行为相关颜色 */
 /* 行为相关颜色 */