lefengyang
2026-08-16 c6ba8b8863ffc5ef0d9dc0bd392966a7700c7812
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
<template>
    <view class="page_bg">
        <uv-navbar title=" " :placeholder="true" :autoBack="true" bgColor="rgba(0,0,0,0)"
            titleStyle="color:#fff"></uv-navbar>
 
        <view class="head_ph">
            <uv-upload :fileList="fileList1" name="1" :maxCount="1" width="200rpx" height="200rpx"
                @afterRead="afterRead" @delete="deletePic">
                <image class="ico_head" src="/static/img/ico_head.png" mode="widthFix"
                    style="width: 200rpx;height: 200rpx;"></image>
            </uv-upload>
            <view class="name">
                上传头像
            </view>
        </view>
 
        <view class="register">
            <view class="item">
                <uv-input placeholder="请输入手机号/邮箱" border="none" v-model="userName"></uv-input>
            </view>
            <view class="item">
                <uv-input placeholder="请输入密码" :password="isEye" border="none" v-model="password"></uv-input>
                <view class="eye" @click="isEye = !isEye">
                    <uv-icon v-if="isEye" name="eye-off" color="#666" size="40rpx"></uv-icon>
                    <uv-icon v-else name="eye" color="#666" size="40rpx"></uv-icon>
                </view>
            </view>
            <view class="item">
                <uv-input placeholder="请输入昵称" border="none" v-model="nickName"></uv-input>
            </view>
            <view class="item">
                <uv-input placeholder="请输入微信号" border="none" v-model="wx"></uv-input>
            </view>
 
            <view class="item_login">
                <navigator class="link" url="/pages/login/login" hover-class="none">
                    已有账号?去登录
                </navigator>
            </view>
            <view class="item_agree">
                <checkbox-group @change="changeAgree">
                    <label class="item_agree_info">
                        <checkbox value="agree" :checked="false" style="transform:scale(0.75)" ></checkbox>
                        同意本应用
                        <navigator class="link" url="/pages/policy/policy?id=1" hover-class="none">《用户协议》</navigator>
                        和
                        <navigator class="link" url="/pages/policy/policy?id=2" hover-class="none">《隐私政策》</navigator>
                    </label>
                </checkbox-group>
            </view>
            <view class="item_btn">
                <uv-button text="注册" color="linear-gradient( 142deg, #6FD2FF 0%, #268DFF 100%)" shape="circle" size="large" @click="clickRegister()"></uv-button>
            </view>
        </view>
 
    </view>
</template>
 
<script>
    import { register } from '@/api/api.js'
    export default {
        data() {
            return {
                userName: '',
                password: '',
                nickName: '',
                wx: '',
                avatar: '',
                fileList1: [],
                baseURL: '',
                agree: 0,
                isEye: true
            }
        },
        onLoad() {
            this.baseURL = uni.$uv.http.config.baseURL
            console.log(this.baseURL)
            
        },
        methods: {
            clickRegister(){
                if(this.fileList1.length == 0){
                    uni.showToast({
                        title: '请上传头像',
                        duration: 2000,
                        icon: 'none'
                    });
                    return
                }
                if(!this.userName){
                    uni.showToast({
                        title: '请输入账号',
                        duration: 2000,
                        icon: 'none'
                    });
                    return
                }
                if(!this.password){
                    uni.showToast({
                        title: '请输入密码',
                        duration: 2000,
                        icon: 'none'
                    });
                    return
                }
                if(!this.nickName){
                    uni.showToast({
                        title: '请输入昵称',
                        duration: 2000,
                        icon: 'none'
                    });
                    return
                }
                if(!this.agree){
                    uni.showToast({
                        title: '请勾选用户协议和隐私政策',
                        duration: 2000,
                        icon: 'none'
                    });
                    return
                }
                
                register({
                    userName: this.userName,
                    password: this.password,
                    nickName: this.nickName,
                    wx: this.wx,
                    avatar: this.fileList1[0].url,
                }).then(res=>{
                    console.log('注册----',res)
                    uni.showToast({
                        title: res.msg,
                        duration: 2000,
                        icon: 'none'
                    });
                    if(res.code == 200){
                        uni.reLaunch({
                            url: '/pages/login/login'
                        });
                    }
                    else{
                        
                    }
                })
            },
            changeAgree(e){
                //console.log(e.detail.value.length)
                this.agree = e.detail.value.length
            },
            // 删除图片
            deletePic(event) {
                this[`fileList${event.name}`].splice(event.index, 1)
            },
            // 新增图片
            async afterRead(event) {
                console.log('event---',event)
                // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
                let lists = [].concat(event.file)
                let fileListLen = this[`fileList${event.name}`].length
                lists.map((item) => {
                    this[`fileList${event.name}`].push({
                        ...item,
                        status: 'uploading',
                        message: '上传中'
                    })
                })
                for (let i = 0; i < lists.length; i++) {
                    const result = await this.uploadFilePromise(lists[i].url)
                    let item = this[`fileList${event.name}`][fileListLen]
                    this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
                        status: 'success',
                        message: '',
                        url: result
                    }))
                    fileListLen++
                }
            },
            uploadFilePromise(url) {
                return new Promise((resolve, reject) => {
                    let a = uni.uploadFile({
                        url: this.baseURL+'/common/uploadFileByAnny', // 仅为示例,非真实的接口地址
                        filePath: url,
                        name: 'file',
                        success: (res) => {
                            console.log('图片-----',JSON.parse(res.data).fileName)
                            setTimeout(() => {
                                resolve(JSON.parse(res.data).fileName)
                            }, 1000)
                        }
                    });
                })
            }
        }
    }
</script>
 
<style lang="scss" scoped>
    
    .register{
        padding:0 60rpx;
        .item_agree{
            display: flex;
            align-items: center;
            font-size: 27rpx;
            color: rgba(0,0,0,0.85);
            line-height: 30rpx;
            margin-top: 80rpx;
            .link{
                font-size: 27rpx;
                color: #3086F3;
            }
            .item_agree_info{
                display: flex;
                align-items: center;
            }
        }
        .item_btn{
            margin-top: 40rpx;
        }
        .item{
            margin-top: 46rpx;
            height: 100rpx;
            background: #ECEFF6;
            border-radius: 23rpx 23rpx 23rpx 23rpx;
            display: flex;
            align-items: center;
            justify-content: space-between;
            box-sizing: border-box;
            padding:0 20rpx;
        }
        .item_login{
            padding:20rpx 0;
            .link{
                font-size: 27rpx;
                color: #3086F3;
                line-height: 40rpx;
            }
        }
    }
    .head_ph {
        flex-shrink: 0;
        width: 200rpx;
        margin: 50rpx auto;
        .name{
            text-align: center;
            font-size: 28rpx;
            line-height: 40rpx;
            margin-top: 20rpx;
        }
        .ico_head {
            width: 200rpx;
            height: 200rpx;
            border-radius: 50%;
            
        }
    }
 
    .page_bg {
        width: 100%;
        min-height: calc(100vh - var(--window-bottom));
        background: url('/static/img/bg_2.jpg') no-repeat center top;
        background-size: 100% auto;
    }
</style>