api按模块单独配置文件

This commit is contained in:
sfmind 2022-05-01 22:39:16 +08:00
parent 083daa657d
commit f7d384e55d
10 changed files with 55 additions and 40 deletions

View File

@ -0,0 +1,15 @@
//请求工具参考https://ext.dcloud.net.cn/plugin?id=392
const { http } = uni.$u
//获得用户收件地址列表
export const getAddressList = params => http.get('/app-api/member/address/list', params)
//创建用户收件地址
export const createAddress = data => http.post('/app-api/member/address/create', data)
//通过ID获得用户收件地址
export const getAddressById = params => http.get('/app-api/member/address/get', { params })
//获得默认的用户收件地址
export const getDefaultUserAddress = params => http.get('/app-api/member/address/get-default', { params })
//更新用户收件地址
export const updateAddress = params => http.put('/app-api/member/address/update', params)
//删除用户收件地址
export const deleteAddress = params => http.delete('/app-api/member/address/delete', {}, { params })

12
yudao-ui-app/api/auth.js Normal file
View File

@ -0,0 +1,12 @@
//请求工具参考https://ext.dcloud.net.cn/plugin?id=392
const { http } = uni.$u
//使用手机 + 密码登录
export const passwordLogin = data => http.post('/app-api/member/login', data)
//退出登录
export const logout = data => http.post('/app-api/member/logout', data)
//发送手机验证码
export const sendSmsCode = data => http.post('/app-api/member/send-sms-code', data)
//使用手机 + 验证码登录
export const smsLogin = data => http.post('/app-api/member/sms-login', data)

View File

@ -0,0 +1,7 @@
//请求工具参考https://ext.dcloud.net.cn/plugin?id=392
const { http } = uni.$u
// 获取滚动图数据
export const getBannerData = params => http.get('/app-api/index', { params })
// 获取滚动通知数据
export const getNoticeData = params => http.get('/app-api/notice', { params })

14
yudao-ui-app/api/user.js Normal file
View File

@ -0,0 +1,14 @@
//请求工具参考https://ext.dcloud.net.cn/plugin?id=392
const { http } = uni.$u
//获取用户信息
export const getUserInfo = params => http.get('/app-api/member/user/get', params)
//修改用户头像
export const updateAvatar = filePath =>
http.upload('/app-api/member/user/update-avatar', {
name: 'avatarFile',
fileType: 'image',
filePath: filePath
})
//修改用户昵称
export const updateNickname = params => http.put('/app-api/member/user/update-nickname', {}, { params })

View File

@ -1,33 +0,0 @@
//请求工具参考https://ext.dcloud.net.cn/plugin?id=392
const { http } = uni.$u
/* login */
//使用手机 + 密码登录
export const passwordLogin = params => http.post('/app-api/member/login', params)
//退出登录
export const logout = params => http.post('/app-api/member/logout', params)
//发送手机验证码
export const sendSmsCode = params => http.post('/app-api/member/send-sms-code', params)
//使用手机 + 验证码登录
export const smsLogin = params => http.post('/app-api/member/sms-login', params)
//获取用户信息
export const getUserInfo = params => http.get('/app-api/member/user/get', params)
//修改用户头像
export const updateAvatar = filePath =>
http.upload('/app-api/member/user/update-avatar', {
name: 'avatarFile',
fileType: 'image',
filePath: filePath
})
//修改用户昵称
export const updateNickname = params =>
http.put('/app-api/member/user/update-nickname', {}, {
params
})
/* index */
// 获取滚动图数据
export const getBannerData = params => http.get('/app-api/index', params)
// 获取滚动通知数据
export const getNoticeData = params => http.get('/app-api/notice', params)

View File

@ -109,7 +109,7 @@
</template> </template>
<script> <script>
import { getBannerData, getNoticeData } from '../../common/api' import { getBannerData, getNoticeData } from '../../api/index'
export default { export default {
components: {}, components: {},

View File

@ -48,7 +48,7 @@
</template> </template>
<script> <script>
import { passwordLogin, sendSmsCode, smsLogin } from '../../common/api' import { passwordLogin, sendSmsCode, smsLogin } from '../../api/auth'
export default { export default {
data() { data() {

View File

@ -51,7 +51,7 @@
</template> </template>
<script> <script>
import { getUserInfo, updateAvatar, updateNickname } from '../../common/api' import { getUserInfo, updateAvatar, updateNickname } from '../../api/user'
export default { export default {
data() { data() {

View File

@ -3,7 +3,7 @@
<view class="user-header"> <view class="user-header">
<view class="user-info" @click="loginOrJump('/pages/profile/profile')"> <view class="user-info" @click="loginOrJump('/pages/profile/profile')">
<u-avatar size="80" :src="userInfo.avatar"></u-avatar> <u-avatar size="80" :src="userInfo.avatar"></u-avatar>
<text class="nick-name">{{ hasLogin ? userInfo.nickname || '游客' : '点击登录' }}</text> <text class="nick-name">{{ hasLogin ? userInfo.nickname || '游客' : '登录/注册' }}</text>
</view> </view>
</view> </view>
@ -90,10 +90,9 @@ export default {
content: '您确定要退出登录吗', content: '您确定要退出登录吗',
success: res => { success: res => {
if (res.confirm) { if (res.confirm) {
console.log('用户点击确定')
this.$store.dispatch('logout') this.$store.dispatch('logout')
} else if (res.cancel) { } else if (res.cancel) {
console.log('用户点击取消') //console.log('')
} }
} }
}) })

View File

@ -1,6 +1,7 @@
import Vue from 'vue' import Vue from 'vue'
import Vuex from 'vuex' import Vuex from 'vuex'
import { getUserInfo, logout } from '@/common/api' import { logout } from '@/api/auth'
import { getUserInfo } from '@/api/user'
Vue.use(Vuex) // vue的插件机制 Vue.use(Vuex) // vue的插件机制