Commit 6ec5cb89 by 李伟康

COMMIT 公共接口

1 parent 84aed90c
import commonApi from './common'
import systemApi from './systemApi'
import userApi from './userApi'
module.exports = {
commonApi,
systemApi
systemApi,
userApi
}
\ No newline at end of file
import http from '../request/http'
module.exports = {
getSmsCode (data) {
data.projectName = 'boutique'
return http.fetch('dj.api.smartcarlife.sms.get.code', data)
},
}
\ No newline at end of file
......@@ -3,23 +3,29 @@ import {
secretKey,
pathEnum,
domain,
djDomain,
merchantDomain,
djSecretKey
} from '../../env'
const HOST = {
scrm: domain,
dj: djDomain,
merchant: merchantDomain
}
class Request {
get (params, returnAll = false) {
return this.request('GET', params, returnAll)
get (params, returnAll = false, hostType) {
return this.request('GET', params, returnAll, hostType)
}
post (params, returnAll = false) {
return this.request('POST', params, returnAll)
post (params, returnAll = false, hostType) {
return this.request('POST', params, returnAll, hostType)
}
fetch (method, data, returnAll = true) {
fetch (method, data, returnAll = true, hostType) {
return this.post({
method,
...data,
},
returnAll
)
}, returnAll, hostType)
}
request (RequestMethods, params, returnAll) {
request (RequestMethods, params, returnAll, hostType = 'dj') {
return new Promise((resolve, reject) => {
let header = RequestMethods === 'POST' ? {
'content-type': 'application/x-www-form-urlencoded'
......@@ -29,9 +35,9 @@ class Request {
let projectName = params.projectName
if (!projectName) projectName = this.getRopProject(params.method)
const path = pathEnum[projectName]
params = this.getData(params)
params = this.getData(params, hostType)
uni.request({
url: `${domain}${path}router?method=${params.method}`,
url: `${HOST[hostType]}${path}router?method=${params.method}`,
data: params,
method: RequestMethods,
header,
......@@ -52,19 +58,9 @@ class Request {
}
if (code == 20 || code == 21) {
uni.hideLoading()
// const thisPage = wx.p.router.getPageInstance(),
// options = Object.keys(thisPage.options)
// let currentRoute = thisPage.route,
// query = []
// if (options.length) {
// options.map(key => {
// query.push(`${key}=${thisPage.options[key]}`)
// })
// }
// if (query.length) currentRoute += `?${query.join('&')}`
// return wx.p.router.redirectTo('/pages/loading/loading', {
// url: `/${currentRoute}`
// })
uni.reLaunch({
url: '/pages/common/login'
})
} else {
if (code == '0') {
resolve(data.data)
......@@ -91,7 +87,7 @@ class Request {
})
})
}
getData (params) {
getData (params, hostType = 'scrm') {
let projectName = params.projectName
if (!projectName) projectName = this.getRopProject(params.method)
else delete params.projectName
......@@ -101,6 +97,10 @@ class Request {
appKey = secretKey[projectName].appKey
secret = secretKey[projectName].secret
}
if (hostType == 'dj') {
appKey = djSecretKey.appKey
secret = djSecretKey.secret
}
let {
sessionId
} = uni.$storage.get()
......@@ -125,7 +125,7 @@ class Request {
const projectName = method.split('.')[2]
return projectName
}
uni_request({
uni_request ({
url,
method = 'GET',
data = {},
......@@ -141,7 +141,7 @@ class Request {
header,
dataType,
responseType,
success(response) {
success (response) {
resolve(response.data)
}
})
......
......@@ -48,6 +48,50 @@ const domain = {
prod: 'https://scrm.glsx.com.cn'
}[target[index]]
const djDomain = {
ip: 'http://192.168.2.59:8292',
// ip: 'http://192.168.2.80:8558',
dev: 'https://dj.dev.glsx.com.cn',
beta: 'https://dj.beta.glsx.com.cn', //预发布 appid: wx9f91c1ec493eb425
uat: 'https://dj.test.glsx.com.cn', //测试 appid: wxe10067a63c1856ac
prod: 'https://dj.glsx.com.cn',
pet: 'https://cdptest.glsx.com.cn' //压测 appid: wx7ce755e425603084
}[target[index]]
const merchantDomain = {
ip: 'http://rop-merchant.dev.glsx.com.cn',
dev: 'http://rop-merchant.dev.glsx.com.cn',
beta: 'https://rop-merchant.beta.glsx.com.cn',
uat: 'https://rop-merchant.test.glsx.com.cn',
prod: 'https://commodity.glsx.com.cn',
pet: ''
}[target[index]]
const djSecretKey = {
ip: {
},
dev: {
appKey: '48e5e13229b82c1b4e6e8c96151f0637',
secret: 'c24619ed7fef02a0ae16328146bca5f97cc6493957a2137b',
},
uat: {
appKey: '48e5e13229b82c1b4e6e8c96151f0637',
secret: 'c24619ed7fef02a0ae16328146bca5f97cc6493957a2137b',
},
beta: {
appKey: 'd7ffc3346fc9a45bccaaa35300d59022',
secret: '4bc07f8868374c49a4661d603377e3106fc9a45bccaaa353',
},
prod: {
appKey: 'd7ffc3346fc9a45bccaaa35300d59022',
secret: '4bc07f8868374c49a4661d603377e3106fc9a45bccaaa353'
},
pet: {
appKey: 'd7ffc3346fc9a45bccaaa35300d59022',
secret: '4bc07f8868374c49a4661d603377e3106fc9a45bccaaa353'
}
}[target[index]]
const pathEnum = {
sso: '/rop-scrm-sso/',
shopmall: '/rop-scrm-shopmall/',
......@@ -62,7 +106,8 @@ const pathEnum = {
sop: '/rop-scrm-sop/',
customercollect: '/rop-scrm-bigdatautil/',
drac: '/rop-scrm-entmicro/',
busassistant: '/rop-scrm-busassistant/'
busassistant: '/rop-scrm-busassistant/',
boutique: '/rop-dj-car-boutique/'
}
const CONFIG_ENV_MAP = {
1: 'develop',
......@@ -75,5 +120,8 @@ module.exports = {
domain,
pathEnum,
secretKey,
env: CONFIG_ENV_MAP[index]
env: CONFIG_ENV_MAP[index],
djDomain,
merchantDomain,
djSecretKey
}
......@@ -7,15 +7,12 @@
<view class="input">
<input
type="tel"
v-model="phone"
v-model="mobile"
placeholder="请输入手机号"
maxlength="11"
>
<template v-if="phone">
<text
class="icon"
@click="phone = ''"
>X</text>
/>
<template v-if="mobile">
<text class="icon" @click="mobile = ''">X</text>
</template>
</view>
<view class="input">
......@@ -24,41 +21,73 @@
v-model="code"
placeholder="请输入验证码"
maxlength="4"
>
/>
<template v-if="code">
<text
class="icon"
@click="code = ''"
>X</text>
<text class="icon" @click="code = ''">X</text>
</template>
<view
:class="['code-btn', { 'code-disabled': count }]"
@click="getSmsCode"
>{{ count ? `重新发送(${count}s)` : '获取验证码' }}</view
>
</view>
<button
class="btn"
:disabled="!phone || !code"
>登录</button>
<button class="btn" :disabled="!mobile || !code">登录</button>
</view>
</view>
</template>
<script>
const phoneRex = /^[1]([3-9])[0-9]{9}$/;
export default {
data () {
data() {
return {
phone: '1',
code: ''
}
mobile: '',
code: '',
count: '',
};
},
onLoad (options) {
uni.$api.commonApi.search().then(res => {
console.log(res)
})
onLoad(options) {
uni.hideLoading();
},
methods: {
// input (e) {
// this.phone = e.detail.value
// }
/**获取验证码 */
async getSmsCode() {
const { mobile, count } = this;
try {
if (!mobile) throw '请输入手机号';
if (!phoneRex.test(mobile)) throw '请输入正确的手机号';
if (count) throw '验证码发送过于频繁,请稍后在试';
this.countDown(60);
uni.showLoading()
const { code, message } = await uni.$api.userApi.getSmsCode({mobile});
uni.hideLoading()
if (code == '0') {
uni.showToast({
title: '验证码已发送',
icon: 'none',
});
this.countDown(60);
} else throw message || '发送验证码失败';
} catch (error) {
uni.hideLoading()
uni.showToast({
title: error,
icon: 'none',
})
}
},
/**验证码倒计时 */
countDown(countDown) {
if (countDown) this.count = countDown;
setTimeout(() => {
let { count } = this;
this.count = --count;
if (count > 0) this.countDown();
else this.count = null;
}, 1e3);
},
},
}
};
</script>
<style lang="scss" scoped>
......@@ -68,7 +97,7 @@ export default {
height: 100%;
left: 0;
top: 0;
background-image: url("https://img02.glsx.com.cn/weapp/resource/app-tape/login/bg.png");
background-image: url('https://img02.glsx.com.cn/weapp/resource/app-tape/login/bg.png');
background-size: 100% 100%;
}
.login {
......@@ -105,6 +134,17 @@ export default {
}
.icon {
margin-left: auto;
flex-shrink: 0;
}
.code-btn {
font-weight: 500;
font-size: 32rpx;
color: #2c66f7;
flex-shrink: 0;
border: none;
}
.code-disabled {
color: #9b9b9e;
}
}
.btn {
......@@ -120,8 +160,8 @@ export default {
color: #ffffff;
}
.btn[disabled]:not([type]),
.btn[disabled][type="default"] {
.btn[disabled][type='default'] {
background: #c9c9c9 !important;
}
}
</style>
\ No newline at end of file
</style>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!