chubiao 1 年之前
父節點
當前提交
4008ad2df1
共有 6 個文件被更改,包括 107 次插入19 次删除
  1. 10 0
      api/dict.js
  2. 5 9
      api/login.js
  3. 13 2
      common/request.js
  4. 1 1
      package.json
  5. 11 1
      pages.json
  6. 67 6
      pages/login/login.vue

+ 10 - 0
api/dict.js

@@ -0,0 +1,10 @@
+import request from '@/common/request.js'
+
+// 登录方法
+export const login = (data) => {
+	return request({
+		url: '/auth/firstLogin',
+		method: 'post',
+		data: data
+	})
+}

+ 5 - 9
api/login.js

@@ -1,4 +1,4 @@
-import request from '@/utils/request'
+import request from '@/common/request.js'
 
 // 注册方法
 export function register(data) {
@@ -10,16 +10,12 @@ export function register(data) {
 }
 
 // 登录方法
-export function login(username, password) {
-	const data = {
-		username,
-		password
-	}
+export const login = (data) => {
 	return request({
 		url: '/auth/firstLogin',
-		headers: {
-			isToken: false
-		},
+		// headers: {
+		// 	isToken: false
+		// },
 		method: 'post',
 		data: data
 	})

+ 13 - 2
common/request.js

@@ -16,7 +16,14 @@ const request = config => {
 		config.header['Authorization'] = 'Bearer ' +
 			'eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyX2lkIjo3MDA0NDMsInVzZXJfa2V5IjoiNjFlMDVkMWItODY1Zi00MGIwLThiOWItM2VjY2I0ZGEzYjAwIiwidXNlcm5hbWUiOiJ5bGpnMjIwMjgyMDAzMiJ9.K16sZmP0X54BsIt5dpPBm5Jw8VLoQR3Vt1VJ8IpdRNChDwZNthxfCBAKPkUAilFtb5NuBIppH54dktTPSV5mNA'
 	}
+
 	console.log("请求:", config, BASE_URL + config.url)
+
+	uni.showLoading({
+		title: '请求中...'
+	})
+
+
 	return new Promise((resolve, reject) => {
 		uni.request({
 			header: config.header,
@@ -30,10 +37,9 @@ const request = config => {
 			const code = res.statusCode || 200
 			const msg = res.data.msg || '未知错误,请反馈给管理员'
 
-
 			if (res.data.code == 500) {
 				uni.showToast({
-					icon:'error',
+					icon: 'error',
 					title: '接口未知异常',
 				})
 				reject(msg)
@@ -58,6 +64,9 @@ const request = config => {
 			}
 
 			resolve(res.data.data)
+			uni.hideLoading()
+
+
 		}).catch(error => {
 			console.log("请求失败:", error)
 			let {
@@ -70,6 +79,8 @@ const request = config => {
 			} else if (message.includes('Request failed with status code')) {
 				message = '系统接口' + message.substr(message.length - 3) + '异常'
 			}
+
+			uni.hideLoading()
 			toast(message)
 			reject(error)
 		})

+ 1 - 1
package.json

@@ -7,4 +7,4 @@
 		"@dcloudio/uni-app": "^2.0.2-3090920231225001",
 		"uview-ui": "^2.0.36"
 	}
-}
+}

+ 11 - 1
pages.json

@@ -65,5 +65,15 @@
 		"navigationBarBackgroundColor": "#F8F8F8",
 		"backgroundColor": "#F8F8F8"
 	},
-	"uniIdRouter": {}
+	"uniIdRouter": {},
+	"condition" : { //模式配置,仅开发期间生效
+		"current": 0, //当前激活的模式(list 的索引项)
+		"list": [
+			{
+				"name": "login", //模式名称
+				"path": "pages/login/login", //启动页面,必选
+				"query": "" //启动参数,在页面的onLoad函数里面得到
+			}
+		]
+	}
 }

+ 67 - 6
pages/login/login.vue

@@ -1,23 +1,84 @@
 <template>
-	<view class="u-line-1">
-		<u-icon name="photo-fill" color="#2979ff" size="28"></u-icon>
-		<u-input v-model="value" type="number" placeholder="请输入手机号" :border="true" clearable />
+	<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="primary" 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>
 </template>
 
 <script>
+	import { setToken } from '@/common/auth.js'
+	import { toast } from '@/common/common.js'
+	import { login } from '@/api/login.js'
+
 	export default {
 		data() {
 			return {
-				value: '',
+				form: {
+					username: '15143018065',
+					password: 'sckj@2022',
+				},
+				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'] },
+					]
+				},
 			}
 		},
-		methods: {
+		onReady() {
+			this.$refs.loginForm.setRules(this.rules)
+		},
 
+		methods: {
+			submitForm() {
+				this.$refs.loginForm.validate().then(() => {
+					login(this.form).then((res) => {
+						if (res.code === 200) {
+							const { data } = res
+							setToken(data.access_token)
+							uni.reLaunch({ url: '/pages/index/index' })
+						} else {
+							toast(res.msg)
+						}
+					})
+				}).catch(() => {})
+			},
+			quickLogin() {
+				console.log('quick login');
+			}
 		}
 	}
 </script>
 
 <style lang="scss">
-	@import "uview-ui/index.scss";
 </style>