瀏覽代碼

http.js 修改

ming 3 年之前
父節點
當前提交
438d2bf802
共有 6 個文件被更改,包括 62 次插入44 次删除
  1. 0 1
      modules/common/feedback.vue
  2. 26 23
      modules/common/version.vue
  3. 1 1
      pages/my/my.vue
  4. 7 1
      services/common.js
  5. 2 2
      utils/config.js
  6. 26 16
      utils/http.js

+ 0 - 1
modules/common/feedback.vue

@@ -98,7 +98,6 @@ const fetchList = () => {
 // fetchList()
 
 const handleSubmit = () => {
-	console.log(curProblem.value);
 	if (!state.detail) {
 		return uni.showToast({
 			title: '请输入问题描述',

+ 26 - 23
modules/common/version.vue

@@ -1,31 +1,34 @@
 <template>
-	<view class="fs-version-list">
-		<view class="fs-version-list-item" v-for="item in vList">
-			<view class="flex justify-between align-center">
-				<view class="fs-version-bd primary">{{item.number}}</view>
-				<view class="fs-version-time">
-					<fs-date-format :date="item.date"></fs-date-format>
-				</view>
-			</view>
-			<view class="title">本次更新</view>
-			<view class="content">{{item.content}}</view>
-		</view>
+	<view>
+		<view class="fs-version-list">
+			<view class="fs-version-list-item" v-for="item in vList" :key="item.number">
+				<view class="flex justify-between align-center">
+					<view class="fs-version-bd primary">{{item.number}}</view>
+					<view class="fs-version-time">
+						<fs-date-format :date="item.date"></fs-date-format>
+					</view>
+				</view>
+				<view class="title">本次更新</view>
+				<view class="content">{{item.content}}</view>
+			</view>
+		</view>
+		<fs-empty v-if="loaded && !vList.length"></fs-empty>
 	</view>
 </template>
 
 <script setup>
-const vList = [
-	{
-		number: '2.0',
-		date: '2021/08/10',
-		content: '更新内容'
-	},
-	{
-		number: '1.0',
-		date: '2021/05/10',
-		content: '更新内容'
-	}
-]
+import { ref, reactive } from 'vue'
+import { getVersionList } from '@/services/common'
+
+let vList = ref([])
+let loaded = ref(false)
+
+getVersionList().then(res => {
+	vList.value = res.data
+	loaded.value = true
+}).catch(err => {
+	loaded.value = true
+})
 </script>
 
 <style lang="scss" scoped>

+ 1 - 1
pages/my/my.vue

@@ -40,7 +40,7 @@
 				<view class="title-hd" >常用工具</view>
 			</template>
 			<fs-grid :columnNum="4">
-				<fs-grid-item v-for="item in 4">
+				<fs-grid-item v-for="(item, index) in 4" :key="index">
 					<fs-avatar src="/static/images/my/invoice.png" size="80rpx"></fs-avatar>
 					<view class="content">我的发票</view>
 				</fs-grid-item>

+ 7 - 1
services/common.js

@@ -27,12 +27,18 @@ export function logout(data) {
 
 // 意见反馈
 export function addAdvice(data) {
-	return http.post('user/advice/add', data)
+	return http.post('user/advice', data)
 }
 export function getAdviceList() {
 	return http.get('user/advice/list')
 }
 
+// 版本信息
+export function getVersionList(data) {
+	return http.get('user/version', data)
+}
+
+
 // 通讯录
 export function getAddrbookList() {
 	return http.get('user/advice/list')

+ 2 - 2
utils/config.js

@@ -1,8 +1,8 @@
-const baseUrl = process.env.NODE_ENV === 'development' ? 'http://johnny-ttj.vaiwan.com' : 'https://zhswapi.sxidc.com'
+const baseUrl = process.env.NODE_ENV === 'development' ? 'https://saishi.sxidc.com' : 'https://zhswapi.sxidc.com'
 
 const config = {
 	baseUrl,
-	apiBaseUrl: baseUrl + '/api/',
+	apiBaseUrl: baseUrl + '/apiApp/1/',
 	httpDefaultOption: {
 		showLoading: true,
 		isAuth: true,

+ 26 - 16
utils/http.js

@@ -2,17 +2,23 @@ import store from '@/store'
 import config from './config'
 import utils from './utils'
 
-const request = (method, url, data) => {
+const request = (method, url, data, opt) => {
 	return new Promise((resolve, reject) => {
+		opt.showLoading && uni.showLoading({
+			title: opt.loadingTitle
+		})
+		
 		uni.request({
 			method,
 			url: utils.isHttp(url) ? url : config.apiBaseUrl + url,
 			header: {
-				Authorization: store.state.token
+				Authorization: store.state.token,
+				...opt.header
 			},
 			data
 		}).then(res => {
-			if (res.code === 201) {
+			const data = res.data
+			if (data.code === 201) {
 				store.commit('setUserInfo', {})
 				
 				// opt.isAuth && uni.navigateTo({
@@ -20,20 +26,19 @@ const request = (method, url, data) => {
 				// })
 			}
 			
-			if (res.code === 200 || res.success) {
-				resolve(res)
+			if (data.code === 200 || data.success) {
+				resolve(data)
 			} else{
 				uni.showToast({
-					title: res.msg,
+					title: data.msg,
 					icon: 'none'
 				})
-				reject(res)
+				reject(data)
 			}
-			
 		}).catch(err => {
 			reject(err)
 		}).finally(() => {
-			uni.hideLoading()
+			opt.showLoading && uni.hideLoading()
 		})
 	})
 }
@@ -44,8 +49,17 @@ const methods = ['GET', 'POST', 'PUT', 'DELETE']
 methods.forEach(method => {
 	http[method.toLowerCase()] = (url, data, options) => {
 		const loadingTitle = method === 'GET' ? '加载中...' : '提交中...'
-		const opt = Object.assign({}, config.httpDefaultOption, { loadingTitle }, options)
-		
+		const opt = Object.assign(
+			{
+				loadingTitle,
+				header: {
+					'content-type': 'application/x-www-form-urlencoded'
+				}
+			}, 
+			config.httpDefaultOption, 
+			options
+		)
+		console.log(opt);
 		if (opt.isAuth) {
 			if (!store.state.token) {
 				// uni.navigateTo({
@@ -57,11 +71,7 @@ methods.forEach(method => {
 			}
 		}
 		
-		opt.showLoading && uni.showLoading({
-			title: opt.loadingTitle
-		})
-		
-		return request(method, url, data)
+		return request(method, url, data, opt)
 	}
 })