Blame view

绿纤uni-app/pages/login/login.vue 4.78 KB
29608708   李宇   增加unia-app和html
1
  <template>
69254297   李宇   最新
2
3
  	<view class="page" :style="{backgroundImage:`url(https://zhgw.028wlkj.com/cdwlMall/zsfwzxt/test/file/static/homePhoto.png)`}">
  		<view style="height: 100vh;width: 100%;position: fixed;bottom: 0;left: 0;">
9854a774   李宇   最新
4
5
  				<!-- 修改切换-->
  			<view style="width: 25%;margin: 0 auto;margin-top: 15vh;">
69254297   李宇   最新
6
  				<image src="../../static/login/logo.jpg" style="width: 100%;border-radius: 18%;" mode="widthFix"></image>
29608708   李宇   增加unia-app和html
7
  			</view>
9854a774   李宇   最新
8
9
  		<!-- 	<view style="width: 80%;margin: 0 auto;margin-top: 15vh;">
  				<image src="/static/login/logo2.png" style="width: 100%;border-radius: 18%;" mode="widthFix"></image>
69254297   李宇   最新
10
11
  			</view> -->
  			<!-- 填写区 -->
8b654f92   李宇   最新
12
  			<view class="input-info" style="margin-top: 8vh;">
69254297   李宇   最新
13
14
15
  				<view class="info">
  					<view class="info-icon">
  						<image src="../../static/login/icon1.png" mode="heightFix"></image>
29608708   李宇   增加unia-app和html
16
  					</view>
69254297   李宇   最新
17
18
  					<input type="text" v-model="formData.username" placeholder="请输入用户名">
  					<view class="more"></view>
29608708   李宇   增加unia-app和html
19
  				</view>
69254297   李宇   最新
20
21
22
23
24
25
26
  				<view class="info">
  					<view class="info-icon">
  						<image src="../../static/login/icon2.png" mode="heightFix"></image>
  					</view>
  					<input v-if="!showPassword" type="password" v-model="formData.password" placeholder="请输入密码">
  					<input v-else type="text" v-model="formData.password" placeholder="请输入密码">
  					<view class="more">
29608708   李宇   增加unia-app和html
27
28
29
  						<u-icon 
  							:name="showPassword ? 'eye-off' : 'eye'" 
  							size="20" 
69254297   李宇   最新
30
  							color="#0FBB59"
29608708   李宇   增加unia-app和html
31
  							@click="togglePassword"
29608708   李宇   增加unia-app和html
32
33
34
  						></u-icon>
  					</view>
  				</view>
69254297   李宇   最新
35
36
37
38
39
  			</view>
  			<!-- 按钮 -->
  			<view class="btn-info">
  				<view class="btn" @click="handleLogin" :class="{ 'btn-disabled': loading }">
  					<text>{{ loading ? '登录中...' : '登录' }}</text>
29608708   李宇   增加unia-app和html
40
41
  				</view>
  			</view>
69254297   李宇   最新
42
  
29608708   李宇   增加unia-app和html
43
  		</view>
69254297   李宇   最新
44
45
46
47
48
49
50
51
52
  		<view
  			style="position: fixed;left: 0;bottom: 49rpx;display: flex;flex-direction: row;justify-content: center;align-items: center;width: 100%;">
  			<view style="display: flex;align-items: center;font-size: 24rpx;color: #333;">
  				<u-checkbox-group @change="checkboxGroupChange" shape="circle">
  					<u-checkbox active-color="#3f9b6a" v-model="checked" name="tongyi" :label-disabled="true"></u-checkbox>
  				</u-checkbox-group>
  				<text style="margin-left: 8rpx;">我已阅读并同意</text>
  				<text style="color:#3f9b6a;margin-left: 4rpx;" @click="goyinsi">《隐私政策》</text>
  			</view>
29608708   李宇   增加unia-app和html
53
54
55
56
57
58
59
60
61
  		</view>
  	</view>
  </template>
  
  <script>
  import md5 from '@/service/md5.js'
  export default {
  	data() {
  		return {
69254297   李宇   最新
62
63
  			checked: null,
  			showTong: false,
29608708   李宇   增加unia-app和html
64
65
66
67
68
69
70
71
  			loading: false,
  			showPassword: false,
  			formData: {
  				username: '',
  				password: ''
  			}
  		}
  	},
29608708   李宇   增加unia-app和html
72
  	onLoad() {
69254297   李宇   最新
73
  		// 页面加载时的初始化
29608708   李宇   增加unia-app和html
74
75
  	},
  	methods: {
69254297   李宇   最新
76
77
  		goyinsi() {
  			uni.navigateTo({
04f9fdae   李宇   最新
78
  				url: '/pages/web/web?url='+encodeURIComponent('https://erp.lvqianmeiye.com/ysxy.html')
69254297   李宇   最新
79
80
81
82
  			});
  		},
  		checkboxGroupChange(val) {
  			this.showTong = val[0]
29608708   李宇   增加unia-app和html
83
84
85
86
87
  		},
  		// 切换密码显示
  		togglePassword() {
  			this.showPassword = !this.showPassword
  		},
29608708   李宇   增加unia-app和html
88
89
  		// 表单验证
  		validateForm() {
69254297   李宇   最新
90
91
92
93
94
95
96
  			if (this.showTong != 'tongyi') {
  				uni.showToast({
  					title: '请阅读并同意隐私政策',
  					icon: 'none'
  				})
  				return false
  			}
29608708   李宇   增加unia-app和html
97
98
99
100
101
102
103
  			if (!this.formData.username.trim()) {
  				uni.showToast({
  					title: '请输入用户名',
  					icon: 'none'
  				})
  				return false
  			}
29608708   李宇   增加unia-app和html
104
105
106
107
108
109
110
  			if (!this.formData.password.trim()) {
  				uni.showToast({
  					title: '请输入密码',
  					icon: 'none'
  				})
  				return false
  			}
29608708   李宇   增加unia-app和html
111
112
  			return true
  		},
69254297   李宇   最新
113
114
  		async getuser() {
  			await this.API.getCurrentUser().then(res => {
a856ffdc   李宇   ```
115
  				console.error(res)
69254297   李宇   最新
116
  				if (res.code === 200) {
a856ffdc   李宇   ```
117
118
119
120
121
  					let date = new Date();
  					uni.setStorageSync('userInfo', res.data.userInfo)
  				}
  			})
  		},
29608708   李宇   增加unia-app和html
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
  		// 处理登录
  		async handleLogin() {
  			if (!this.validateForm()) {
  				return
  			}
  			
  			this.loading = true
  			
  			try {
  				// 对密码进行MD5加密
  				const password = md5.hex_md5(this.formData.password)
  				const res = await this.API.AppLogin({
  					account: this.formData.username,
  					password: password
  				})
  				
  				if (res.code === 200 || res.success) {
  					// 登录成功
69254297   李宇   最新
140
  					const { token } = res.data
29608708   李宇   增加unia-app和html
141
142
143
  					
  					// 保存token和用户信息
  					uni.setStorageSync('token', token)
a856ffdc   李宇   ```
144
  					await this.getuser()
29608708   李宇   增加unia-app和html
145
146
147
148
149
150
151
152
  					uni.showToast({
  						title: '登录成功',
  						icon: 'success'
  					})
  
  					// 延迟跳转
  					setTimeout(() => {
  						uni.reLaunch({
69254297   李宇   最新
153
  							url: '/pages/home/home'
29608708   李宇   增加unia-app和html
154
155
156
157
158
159
  						})
  					}, 1500)
  					
  				} else {
  					// 登录失败
  					uni.showToast({
255a0353   李宇   最新
160
  						title: res.msg || '登录失败,请重试',
29608708   李宇   增加unia-app和html
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
  						icon: 'none'
  					})
  				}
  				
  			} catch (error) {
  				console.error('登录失败:', error)
  				uni.showToast({
  					title: '网络错误,请稍后重试',
  					icon: 'none'
  				})
  			} finally {
  				this.loading = false
  			}
  		}
  	}
  }
  </script>
  
69254297   李宇   最新
179
180
  <style scoped lang="scss">
  @import './login.scss';
29608708   李宇   增加unia-app和html
181
  
69254297   李宇   最新
182
183
184
  .btn-disabled {
  	background-color: #ccc !important;
  	opacity: 0.6;
29608708   李宇   增加unia-app和html
185
  }
29608708   李宇   增加unia-app和html
186
  </style>