Commit 6ec5cb89 by 李伟康

COMMIT 公共接口

1 parent 84aed90c
import commonApi from './common' import commonApi from './common'
import systemApi from './systemApi' import systemApi from './systemApi'
import userApi from './userApi'
module.exports = { module.exports = {
commonApi, commonApi,
systemApi systemApi,
userApi
} }
\ No newline at end of file \ 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 \ No newline at end of file
...@@ -3,23 +3,29 @@ import { ...@@ -3,23 +3,29 @@ import {
secretKey, secretKey,
pathEnum, pathEnum,
domain, domain,
djDomain,
merchantDomain,
djSecretKey
} from '../../env' } from '../../env'
const HOST = {
scrm: domain,
dj: djDomain,
merchant: merchantDomain
}
class Request { class Request {
get (params, returnAll = false) { get (params, returnAll = false, hostType) {
return this.request('GET', params, returnAll) return this.request('GET', params, returnAll, hostType)
} }
post (params, returnAll = false) { post (params, returnAll = false, hostType) {
return this.request('POST', params, returnAll) return this.request('POST', params, returnAll, hostType)
} }
fetch (method, data, returnAll = true) { fetch (method, data, returnAll = true, hostType) {
return this.post({ return this.post({
method, method,
...data, ...data,
}, }, returnAll, hostType)
returnAll
)
} }
request (RequestMethods, params, returnAll) { request (RequestMethods, params, returnAll, hostType = 'dj') {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let header = RequestMethods === 'POST' ? { let header = RequestMethods === 'POST' ? {
'content-type': 'application/x-www-form-urlencoded' 'content-type': 'application/x-www-form-urlencoded'
...@@ -29,9 +35,9 @@ class Request { ...@@ -29,9 +35,9 @@ class Request {
let projectName = params.projectName let projectName = params.projectName
if (!projectName) projectName = this.getRopProject(params.method) if (!projectName) projectName = this.getRopProject(params.method)
const path = pathEnum[projectName] const path = pathEnum[projectName]
params = this.getData(params) params = this.getData(params, hostType)
uni.request({ uni.request({
url: `${domain}${path}router?method=${params.method}`, url: `${HOST[hostType]}${path}router?method=${params.method}`,
data: params, data: params,
method: RequestMethods, method: RequestMethods,
header, header,
...@@ -52,19 +58,9 @@ class Request { ...@@ -52,19 +58,9 @@ class Request {
} }
if (code == 20 || code == 21) { if (code == 20 || code == 21) {
uni.hideLoading() uni.hideLoading()
// const thisPage = wx.p.router.getPageInstance(), uni.reLaunch({
// options = Object.keys(thisPage.options) url: '/pages/common/login'
// 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}`
// })
} else { } else {
if (code == '0') { if (code == '0') {
resolve(data.data) resolve(data.data)
...@@ -91,7 +87,7 @@ class Request { ...@@ -91,7 +87,7 @@ class Request {
}) })
}) })
} }
getData (params) { getData (params, hostType = 'scrm') {
let projectName = params.projectName let projectName = params.projectName
if (!projectName) projectName = this.getRopProject(params.method) if (!projectName) projectName = this.getRopProject(params.method)
else delete params.projectName else delete params.projectName
...@@ -101,6 +97,10 @@ class Request { ...@@ -101,6 +97,10 @@ class Request {
appKey = secretKey[projectName].appKey appKey = secretKey[projectName].appKey
secret = secretKey[projectName].secret secret = secretKey[projectName].secret
} }
if (hostType == 'dj') {
appKey = djSecretKey.appKey
secret = djSecretKey.secret
}
let { let {
sessionId sessionId
} = uni.$storage.get() } = uni.$storage.get()
...@@ -125,7 +125,7 @@ class Request { ...@@ -125,7 +125,7 @@ class Request {
const projectName = method.split('.')[2] const projectName = method.split('.')[2]
return projectName return projectName
} }
uni_request({ uni_request ({
url, url,
method = 'GET', method = 'GET',
data = {}, data = {},
...@@ -141,7 +141,7 @@ class Request { ...@@ -141,7 +141,7 @@ class Request {
header, header,
dataType, dataType,
responseType, responseType,
success(response) { success (response) {
resolve(response.data) resolve(response.data)
} }
}) })
......
...@@ -48,6 +48,50 @@ const domain = { ...@@ -48,6 +48,50 @@ const domain = {
prod: 'https://scrm.glsx.com.cn' prod: 'https://scrm.glsx.com.cn'
}[target[index]] }[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 = { const pathEnum = {
sso: '/rop-scrm-sso/', sso: '/rop-scrm-sso/',
shopmall: '/rop-scrm-shopmall/', shopmall: '/rop-scrm-shopmall/',
...@@ -62,7 +106,8 @@ const pathEnum = { ...@@ -62,7 +106,8 @@ const pathEnum = {
sop: '/rop-scrm-sop/', sop: '/rop-scrm-sop/',
customercollect: '/rop-scrm-bigdatautil/', customercollect: '/rop-scrm-bigdatautil/',
drac: '/rop-scrm-entmicro/', drac: '/rop-scrm-entmicro/',
busassistant: '/rop-scrm-busassistant/' busassistant: '/rop-scrm-busassistant/',
boutique: '/rop-dj-car-boutique/'
} }
const CONFIG_ENV_MAP = { const CONFIG_ENV_MAP = {
1: 'develop', 1: 'develop',
...@@ -75,5 +120,8 @@ module.exports = { ...@@ -75,5 +120,8 @@ module.exports = {
domain, domain,
pathEnum, pathEnum,
secretKey, secretKey,
env: CONFIG_ENV_MAP[index] env: CONFIG_ENV_MAP[index],
djDomain,
merchantDomain,
djSecretKey
} }
...@@ -7,15 +7,12 @@ ...@@ -7,15 +7,12 @@
<view class="input"> <view class="input">
<input <input
type="tel" type="tel"
v-model="phone" v-model="mobile"
placeholder="请输入手机号" placeholder="请输入手机号"
maxlength="11" maxlength="11"
> />
<template v-if="phone"> <template v-if="mobile">
<text <text class="icon" @click="mobile = ''">X</text>
class="icon"
@click="phone = ''"
>X</text>
</template> </template>
</view> </view>
<view class="input"> <view class="input">
...@@ -24,41 +21,73 @@ ...@@ -24,41 +21,73 @@
v-model="code" v-model="code"
placeholder="请输入验证码" placeholder="请输入验证码"
maxlength="4" maxlength="4"
> />
<template v-if="code"> <template v-if="code">
<text <text class="icon" @click="code = ''">X</text>
class="icon"
@click="code = ''"
>X</text>
</template> </template>
<view
:class="['code-btn', { 'code-disabled': count }]"
@click="getSmsCode"
>{{ count ? `重新发送(${count}s)` : '获取验证码' }}</view
>
</view> </view>
<button <button class="btn" :disabled="!mobile || !code">登录</button>
class="btn"
:disabled="!phone || !code"
>登录</button>
</view> </view>
</view> </view>
</template> </template>
<script> <script>
const phoneRex = /^[1]([3-9])[0-9]{9}$/;
export default { export default {
data () { data() {
return { return {
phone: '1', mobile: '',
code: '' code: '',
} count: '',
};
}, },
onLoad (options) { onLoad(options) {
uni.$api.commonApi.search().then(res => { uni.hideLoading();
console.log(res)
})
}, },
methods: { 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> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
...@@ -68,7 +97,7 @@ export default { ...@@ -68,7 +97,7 @@ export default {
height: 100%; height: 100%;
left: 0; left: 0;
top: 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%; background-size: 100% 100%;
} }
.login { .login {
...@@ -105,6 +134,17 @@ export default { ...@@ -105,6 +134,17 @@ export default {
} }
.icon { .icon {
margin-left: auto; 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 { .btn {
...@@ -120,8 +160,8 @@ export default { ...@@ -120,8 +160,8 @@ export default {
color: #ffffff; color: #ffffff;
} }
.btn[disabled]:not([type]), .btn[disabled]:not([type]),
.btn[disabled][type="default"] { .btn[disabled][type='default'] {
background: #c9c9c9 !important; background: #c9c9c9 !important;
} }
} }
</style>
\ No newline at end of file \ 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!