Browse Source

feat:连接数据接口

xianna.liang 8 months ago
parent
commit
6d6fdddd49
6 changed files with 221 additions and 18 deletions
  1. 9 0
      api/ChatApp.js
  2. 103 1
      package-lock.json
  3. 4 1
      package.json
  4. 42 15
      pages/index15/index15.vue
  5. 1 1
      pages/index32/index32.vue
  6. 62 0
      until/request.js

+ 9 - 0
api/ChatApp.js

@@ -0,0 +1,9 @@
+import request from '../until/request'    // 引入封装的axios
+
+export function getDataList(data){
+	return request({
+		url:'/api/ApiChat/ChatApp',
+		method:'post',		
+		params:data
+	})
+}

+ 103 - 1
package-lock.json

@@ -7,7 +7,109 @@
     "": {
       "name": "chat",
       "version": "1.0.0",
-      "license": "ISC"
+      "license": "ISC",
+      "dependencies": {
+        "axios": "^1.7.7"
+      }
+    },
+    "node_modules/asynckit": {
+      "version": "0.4.0",
+      "resolved": "https://registry.npmmirror.com/asynckit/-/asynckit-0.4.0.tgz",
+      "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==",
+      "license": "MIT"
+    },
+    "node_modules/axios": {
+      "version": "1.7.7",
+      "resolved": "https://registry.npmmirror.com/axios/-/axios-1.7.7.tgz",
+      "integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==",
+      "license": "MIT",
+      "dependencies": {
+        "follow-redirects": "^1.15.6",
+        "form-data": "^4.0.0",
+        "proxy-from-env": "^1.1.0"
+      }
+    },
+    "node_modules/combined-stream": {
+      "version": "1.0.8",
+      "resolved": "https://registry.npmmirror.com/combined-stream/-/combined-stream-1.0.8.tgz",
+      "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
+      "license": "MIT",
+      "dependencies": {
+        "delayed-stream": "~1.0.0"
+      },
+      "engines": {
+        "node": ">= 0.8"
+      }
+    },
+    "node_modules/delayed-stream": {
+      "version": "1.0.0",
+      "resolved": "https://registry.npmmirror.com/delayed-stream/-/delayed-stream-1.0.0.tgz",
+      "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
+      "license": "MIT",
+      "engines": {
+        "node": ">=0.4.0"
+      }
+    },
+    "node_modules/follow-redirects": {
+      "version": "1.15.9",
+      "resolved": "https://registry.npmmirror.com/follow-redirects/-/follow-redirects-1.15.9.tgz",
+      "integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==",
+      "funding": [
+        {
+          "type": "individual",
+          "url": "https://github.com/sponsors/RubenVerborgh"
+        }
+      ],
+      "license": "MIT",
+      "engines": {
+        "node": ">=4.0"
+      },
+      "peerDependenciesMeta": {
+        "debug": {
+          "optional": true
+        }
+      }
+    },
+    "node_modules/form-data": {
+      "version": "4.0.0",
+      "resolved": "https://registry.npmmirror.com/form-data/-/form-data-4.0.0.tgz",
+      "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
+      "license": "MIT",
+      "dependencies": {
+        "asynckit": "^0.4.0",
+        "combined-stream": "^1.0.8",
+        "mime-types": "^2.1.12"
+      },
+      "engines": {
+        "node": ">= 6"
+      }
+    },
+    "node_modules/mime-db": {
+      "version": "1.52.0",
+      "resolved": "https://registry.npmmirror.com/mime-db/-/mime-db-1.52.0.tgz",
+      "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
+      "license": "MIT",
+      "engines": {
+        "node": ">= 0.6"
+      }
+    },
+    "node_modules/mime-types": {
+      "version": "2.1.35",
+      "resolved": "https://registry.npmmirror.com/mime-types/-/mime-types-2.1.35.tgz",
+      "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
+      "license": "MIT",
+      "dependencies": {
+        "mime-db": "1.52.0"
+      },
+      "engines": {
+        "node": ">= 0.6"
+      }
+    },
+    "node_modules/proxy-from-env": {
+      "version": "1.1.0",
+      "resolved": "https://registry.npmmirror.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
+      "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==",
+      "license": "MIT"
     }
   }
 }

+ 4 - 1
package.json

@@ -8,5 +8,8 @@
   "keywords": [],
   "author": "",
   "license": "ISC",
-  "description": ""
+  "description": "",
+  "dependencies": {
+    "axios": "^1.7.7"
+  }
 }

+ 42 - 15
pages/index15/index15.vue

@@ -4,13 +4,13 @@
 			<view class="sidebar-left"></view>
 			<view class="body">
 				<view class="head">
-					<text>uniapp聊天框</text>
+					<text>睿宝AI</text>
 				</view>
 				<view class="list-wrap">
 					<scroll-view id="content-box" scroll-y="true" class="scrollview" :scroll-top="msgList.scrollTop">
 						<!-- 聊天主体 -->
 						<view id="content-overflow">
-							<view class="scrollview-item" v-for="(item,index) in msgList.myList" :key='index'>
+							<view class="scrollview-item" v-for="(item,index) in msgList.chatList" :key='index'>
 								<!-- user方-聊天内容 -->
 								<view class="item self" v-if="item.userContent != ''">
 									<image class="avtar" src="../../static/user-avatar.png" mode="aspectFit"></image>
@@ -55,30 +55,46 @@
 		onShow
 	} from '@dcloudio/uni-app'
 
+	import {
+		getDataList
+	} from '../../api/ChatApp.js'
+
+	import axios from 'axios';
+	// import display from '../../theme/display';
+
 	const msgList = reactive({
 		chatMsg: '',
-		myList: [{
-			userContent: '',
-			otherContent: '',
-			image: ''
-		}, ],
+		chatList: [],
 		// 滚动距离
 		scrollTop: 0,
-		boxWord: '选择无处不在,面朝大海春暖花开是海子的选择,人不是生来被打败的是海明威的选择,人固有一死,或重于泰山,或轻于鸿毛,是司马迁的选择,选择是一次又一次自我重塑的过程,让我们不断地成长,不断地完善,如果说人生是一次不断选择的旅程,那么当千帆阅尽最终留下的就是一片属于自己的独一无二的风景   ——董卿《朗读者》'
+		boxWord: '选择无处不在,面朝大海春暖花开是海子的选择,人不是生来被打败的是海明威的选择,人固有一死,或重于泰山,或轻于鸿毛,是司马迁的选择,选择是一次又一次自我重塑的过程,让我们不断地成长,不断地完善,如果说人生是一次不断选择的旅程,那么当千帆阅尽最终留下的就是一片属于自己的独一无二的风景   ——董卿《朗读者》',
+		timer: null,
+		textCount: 0,
+		otherContent: ''
 	})
 
 	// 发送消息
-	const handleSend = (() => {
+	const handleSend = async () => {
+		const data = {
+			AppId: '0c8ff06b-91d9-43f7-b61e-ca5da1db15d4',
+			AId: 'TK1234',
+			content: ''
+		}
 		if (msgList.chatMsg != '') {
 			let obj = {
-				otherContent: msgList.boxWord,
-				userContent: msgList.chatMsg,
+				otherContent: '',
+				userContent: '',
 				image: ""
 			}
-			msgList.myList.push(obj)
+			data.content = msgList.chatMsg
+			obj.userContent = msgList.chatMsg
+			obj.otherContent = await GetNewsList(data)
+			msgList.chatList.push(obj)
 		}
-		msgList.chatMsg = ''
-	})
+
+		msgList.otherContent = ''
+	}
+
 
 	// 滚动条回到最底部
 	const scrollToBottom = (() => {
@@ -97,9 +113,20 @@
 		})
 	})
 	//滚动至聊天底部
-	watch(msgList.myList, (newVal) => {
+	watch(msgList.chatList, (newVal) => {
 		scrollToBottom()
 	})
+
+
+
+	// 调用数据接口
+	const GetNewsList = async (data) => {
+		console.log(111)
+		msgList.chatMsg = ''
+		var res = await getDataList(data)
+		console.log(res)
+		return res
+	}
 </script>
 
 <style>

+ 1 - 1
pages/index32/index32.vue

@@ -5,7 +5,7 @@
 			<view class="sidebar-left"></view>
 			<view class="body">
 				<view class="head">
-					<text>uniapp聊天框</text>
+					<text>睿宝AI</text>
 				</view>
 				<view class="list-wrap">
 					<scroll-view id="content-box" scroll-y="true" class="scrollview" :scroll-top="msgList.scrollTop">

+ 62 - 0
until/request.js

@@ -0,0 +1,62 @@
+import Axios from 'axios'
+// 创建axios
+const axios = Axios.create({
+	headers: {
+		'Content-Type': 'application/json'
+	},
+	timeout: 600000, // 超时
+	baseURL: 'http://192.168.0.166:5000' // 请求接口地址,这里使用本项目地址,因为我们是前后端分离,后面需要在vue.config.js里面配置代理,实际请求得地址不是这个。
+})
+
+// 请求拦截
+axios.interceptors.request.use(req => {
+  if (req.method === 'get') {
+    const url = req.url
+    const t = new Date().getTime()
+    if (url.indexOf('?') >= 0) {
+      req.url = `${url}&t=${t}`
+    } else {
+      req.url = `${url}?t=${t}`
+    }
+  }
+  return req
+})
+
+// 响应拦截
+axios.interceptors.response.use(
+	response => {
+		return response.data
+	},
+	error => {
+		// 响应失败统一处理
+		// const { response } = error
+		// if (response) {
+		//   switch (response.status) {
+		//     case 400:
+		//       window.$vm.$message.error('请求无效')
+		//       break
+		//     case 401:
+		//       window.$vm.$message.error({ message: '尚未登录请重新登录' })
+		//       break
+		//     case 403:
+		//       window.$vm.$message.error('您没有权限这样做,请联系管理员')
+		//       break
+		//     case 404:
+		//       window.$vm.$message.error('请求未找到')
+		//       break
+		//     case 500:
+		//       window.$vm.$message.error('系统异常')
+		//       break
+		//     case 504:
+		//       window.$vm.$message.error('请求超时,请稍后再试')
+		//       break
+		//     default:
+		//       window.$vm.$message.error('系统异常')
+		//       break
+		//   }
+		// }
+		// return Promise.reject(error)
+		console.log(error)
+	}
+)
+export default axios