Skip to content

Commit 60f823b

Browse files
committed
uni.request的使用
1 parent 6b5496a commit 60f823b

File tree

8 files changed

+126
-7
lines changed

8 files changed

+126
-7
lines changed

mt_nuxt214/package-lock.json

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mt_nuxt214/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
},
1313
"dependencies": {
1414
"@amap/amap-jsapi-loader": "^1.0.1",
15+
"@koa/cors": "^5.0.0",
1516
"@koa/multer": "^3.0.2",
1617
"@nuxtjs/axios": "^5.3.6",
1718
"cheerio": "^1.0.0-rc.12",

mt_nuxt214/server/api/user.js

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const user_router = new Router({
77
const Redis = require("ioredis")
88
const redis = new Redis()
99

10-
const { isEmail } = require('methods-util/dist/node/methods_util.cjs')
10+
const { isEmail,isStrictMobile } = require('methods-util/dist/node/methods_util.cjs')
1111
const { aesEncode, aesDecode, SmtpServer, createSlat, hash256, formatDate } = require('../util')
1212

1313
user_router.post('/signup', async ctx => {
@@ -274,4 +274,52 @@ user_router.post('/change/password', async ctx => {
274274
}
275275
})
276276

277+
278+
// 移动平台
279+
user_router.post('/m_signin',async ctx =>{
280+
let { user, password } = ctx.request.body
281+
282+
if (!user || !password) {
283+
return ctx.body = {
284+
code: -1,
285+
msg:"账号和密码不能为空"
286+
}
287+
}
288+
289+
if (!(isEmail(user) || isStrictMobile(user))) {
290+
return ctx.body = {
291+
code: -1,
292+
msg:"不是一个有效的账号"
293+
}
294+
}
295+
296+
try{
297+
let userRes = await ctx.state.$mysql.query(`select slat from mt_users where email="${user}" or iphone="${user}"`)
298+
299+
if (userRes[0].length == 0) {
300+
let createTime = parseInt(Date.now() / 1000)
301+
let nickname = `NF` + parseInt(Math.random() * 1e10)
302+
// 加盐加密
303+
let slat = createSlat()
304+
let pwd = hash256(slat + password)
305+
306+
const [rows] = await ctx.state.$mysql.execute(`INSERT INTO mt_users (username,${user.includes('@') ? 'email' : 'iphone'},password,slat,grade,create_time) VALUES (?,?,?,?,?,?);`, [nickname, user, pwd, slat, grade, createTime])
307+
if (rows.affectedRows === 1) {
308+
309+
}else{
310+
return ctx.body = {
311+
code:-1,
312+
msg:"无效账户~账号注册失败"
313+
}
314+
}
315+
}
316+
317+
return ctx.body = {
318+
msg:"登录流程"
319+
}
320+
}catch(err){
321+
console.log(err)
322+
}
323+
})
324+
277325
module.exports = user_router

mt_nuxt214/server/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ const session = require('koa-generic-session');
44
const redisStore = require('koa-redis');
55
const consola = require('consola')
66
const { Nuxt, Builder } = require('nuxt')
7+
const cors = require('@koa/cors');
78

89
const mysql = require("mysql2/promise")
910
const CONF = require('./conf')
1011

1112
const app = new Koa()
13+
app.use(cors());
1214

1315
app.use(async (ctx, next) => {
1416

mt_uniapp/.hbuilderx/launch.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{ // launch.json 配置了启动调试时相关设置,configurations下节点名称可为 app-plus/h5/mp-weixin/mp-baidu/mp-alipay/mp-qq/mp-toutiao/mp-360/
2+
// launchtype项可配置值为local或remote, local代表前端连本地云函数,remote代表前端连云端云函数
3+
"version": "0.0",
4+
"configurations": [{
5+
"default" :
6+
{
7+
"launchtype" : "local"
8+
},
9+
"mp-weixin" :
10+
{
11+
"launchtype" : "local"
12+
},
13+
"type" : "uniCloud"
14+
}
15+
]
16+
}

mt_uniapp/src/pages/index/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<text class="search-text">请输入商家名、品类或者商圈</text>
1010
<text class="search-btn">搜索</text>
1111
</navigator>
12-
<navigator hover-class="none" class="normal" url="/">
12+
<navigator hover-class="none" class="normal" url="/pages/login/login">
1313
<text class="iconfont icon-user">&#xe62e;</text>
1414
</navigator>
1515
</view>

mt_uniapp/src/pages/login/login.vue

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<view class="wrapper">
66
<view :class="['email-num-wrapper',focus_val == 'email' ? 'active' : '']">
7-
<input class="email-num-input" v-model="email" type="email" placeholder="请输入邮箱" autocomplete="off" @focus="InputFocus('email')" @blur="focus_val=''"/>
7+
<input class="email-num-input" v-model="email" type="email" placeholder="请输入邮箱/手机号" autocomplete="off" @focus="InputFocus('email')" @blur="focus_val=''"/>
88
<text class="iconfont clear-input" @click="email=''" v-show="!!email">&#xe60e;</text>
99
</view>
1010
<view :class="['verify-code-wrapper',focus_val == 'pwd' ? 'active' : '']">
@@ -14,11 +14,14 @@
1414
<navigator class="retrievepassword" hover-class="none" url="/pages/useraccount/retrievepassword">忘记密码</navigator>
1515
</view>
1616
<text class="account-tip" v-show="!!accountTip">{{ accountTip }}</text>
17-
<button class="login-btn" hover-class="none" type="default" @click="login">登录</button>
17+
<button class="login-btn" hover-class="none" type="default" :disabled="!email || !pwd" @click="login">登录</button>
18+
<text class="signup-tip">未注册的邮箱/手机号验证后自动创建美团账户</text>
1819
<view class="user-confirm">
19-
<text class="confirm-tip">请先阅读并勾选用户协议</text>
20+
<text class="confirm-tip" :style="confirmTipStyle">请先阅读并勾选用户协议</text>
2021
<view class="confirm-wrapper">
21-
<label><checkbox style="transform:scale(0.7);" value="cb" activeBackgroundColor="#ffd100" color="#ccc" /></label>
22+
<checkbox-group @change="handleCheckboxChange">
23+
<label><checkbox style="transform:scale(0.7);" value="license" activeBackgroundColor="#ffd100" color="#ccc" /></label>
24+
</checkbox-group>
2225
<view class="confirm-text">
2326
<text>我已阅读并同意</text>
2427
<text @click="gotoView('https://rules-center.meituan.com/m/detail/4')" style="color: #3488ff" >《美团用户协议》、</text>
@@ -37,11 +40,22 @@ export default {
3740
return {
3841
accountTip: "", // 邮箱或密码错误,请重新输入
3942
showPassword: true,
43+
readLic: false,
44+
checkLic:false,
4045
focus_val: "",
4146
email: "",
4247
pwd: ""
4348
};
4449
},
50+
computed:{
51+
confirmTipStyle(){
52+
if(this.readLic == false){
53+
return "visibility: hidden;"
54+
}else{
55+
return "visibility: visible;"
56+
}
57+
}
58+
},
4559
methods: {
4660
changePassword: function () {
4761
this.showPassword = !this.showPassword;
@@ -54,8 +68,30 @@ export default {
5468
url: '/pages/common/webview?url=' + url
5569
})
5670
},
71+
handleCheckboxChange(event){
72+
if(event.mp.detail.value.indexOf('license') != -1){
73+
this.checkLic = true
74+
this.readLic = false
75+
}else{
76+
this.checkLic = false
77+
}
78+
},
5779
login(){
58-
80+
if(!this.checkLic){
81+
this.readLic = true
82+
return false
83+
}
84+
const requestTask = uni.request({
85+
url: 'http://localhost:3000/user/m_signin',
86+
method:"POST",
87+
data: {
88+
user: this.email,
89+
password: this.pwd
90+
},
91+
success: function(res) {
92+
93+
}
94+
});
5995
}
6096
},
6197
};
@@ -110,6 +146,14 @@ export default {
110146
.login-btn{
111147
margin-top: 80rpx;
112148
}
149+
.signup-tip{
150+
margin-top:24rpx;
151+
font-size:24rpx;
152+
color: rgba(0,0,0,0.50);
153+
display: inline-block;
154+
width: 100%;
155+
text-align: center;
156+
}
113157
.user-confirm{
114158
.confirm-tip{
115159
display: inline-block;
2.76 MB
Binary file not shown.

0 commit comments

Comments
 (0)