index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. <template>
  2. <view class="content">
  3. <!-- <navigation-custom :config="config" :scrollTop="scrollTopNav" @customConduct="customConduct" :scrollMaxHeight="scrollMaxHeight" /> -->
  4. <scroll-view id="scrollview" class='chat-box' :style="{height: style.contentViewHeight + 'px'}" scroll-y="true"
  5. :scroll-with-animation="false" :scroll-top="scrollTop" @scrolltoupper="lower()">
  6. <view class="tips-box">
  7. {{nowTime}}
  8. </view>
  9. <view class="tips-box tips-title">
  10. 您好,智能投顾很高兴为您服务!
  11. </view>
  12. <view class="talk-box">
  13. <view class="talk-head-box">
  14. <image src="../../static/rabotHead.png" mode="" class="talk-head"></image>
  15. </view>
  16. <view class="talk-content">您好,智能顾投很高兴为您服务!</view>
  17. </view>
  18. <view v-for="chat in talkList" :key="chat.talkType" class="m-item">
  19. <view class="talk-box talk-box-end" v-show="chat.content">
  20. <view class="talk-content">{{chat.content}}</view>
  21. <view class="talk-head-box">
  22. <image :src='userHeadUrl' mode="" class="talk-head"></image>
  23. </view>
  24. </view>
  25. <view class="talk-box">
  26. <view class="talk-head-box">
  27. <image :src='rabotHeadImg' mode="" class="talk-head"></image>
  28. </view>
  29. <view class="talk-content">{{chat.reply}}</view>
  30. </view>
  31. </view>
  32. </scroll-view>
  33. <view class="send-box" :style="{ 'padding-bottom' : isShowKeyBoard + 'px'}">
  34. <input type="text" class="enter-box" v-model="inputInfo" :adjust-position="true"
  35. @focus="getInputFocus" @blur="getInputBlur" />
  36. <button type="primary" class="submit-message" @click="sendInputInfo()">发送</button>
  37. </view>
  38. <drag-button :isDock="true" :existTabBar="true" @btnClick="goUserSelf" />
  39. </view>
  40. </template>
  41. <script>
  42. // import navigationCustom from "../../components/struggler-navigationCustom/navigation-custom";
  43. import dragButton from "../../components/drag-button/drag-button.vue";
  44. var md5 = require("../../common/md5.js");
  45. var page = 1;
  46. export default {
  47. data() {
  48. return {
  49. title: 'RABOT',
  50. nowTime: '',
  51. nowHeight: '622px',
  52. inputInfo: '',
  53. isShowKeyBoard:0,
  54. rabotHeadImg: "../../static/rabotHead.png",
  55. userHeadUrl: getApp().globalData.user_headUrl || '../../static/userDefault.png',
  56. talkList: [],
  57. config: {
  58. title: "阿拉丁神灯", //title
  59. bgcolor: "#fff", //背景颜色
  60. fontcolor: "black", //文字颜色,默认白色
  61. type: 3, //type 1,3胶囊 2,4无胶囊模式
  62. transparent: false, //是否背景透明 默认白色
  63. linear: true, //是为开启下滑渐变
  64. share: true, //是否将主页按钮显示为分享按钮
  65. menuIcon: "../../static/icon/iconfont-user.png", //当type为3或者4的时候左边的icon文件位置,注意位置与当前页面不一样
  66. // menuText:"返回", 当type为3或4的时候icon右边的文字
  67. },
  68. scrollTopNav: 0, // 当linear为true的时候需要通过onpagescroll传递参数
  69. scrollMaxHeight: 200 ,//滑动的高度限制,超过这个高度即背景全部显示
  70. scrollTop:0,
  71. scrollRequestEnable: true,
  72. pageSize:10,
  73. style: {
  74. pageHeight: 0,
  75. contentViewHeight: 0,
  76. footViewHeight: 90,
  77. mitemHeight: 0
  78. },
  79. }
  80. },
  81. components: {
  82. //navigationCustom
  83. dragButton
  84. },
  85. onPageScroll(e) {
  86. this.scrollTopNav = e.scrollTop;
  87. },
  88. onLoad() {
  89. this.userLogin();
  90. this.getEquipmentHeight();
  91. },
  92. onShow() {
  93. this.getNowTime();
  94. },
  95. methods: {
  96. userLogin(){
  97. uni.login({
  98. success: (res) => {
  99. this.getCodeRabot(res)
  100. }
  101. });
  102. },
  103. getCodeRabot(res){
  104. let that = this;
  105. uni.request({
  106. url:getApp().globalData.shareUrl, //需要设置为全局
  107. method: 'POST',
  108. header: {
  109. 'content-type': 'application/x-www-form-urlencoded'
  110. },
  111. data: {
  112. method: 'login',
  113. timestamp: getApp().globalData.globalTimestamp, //Date.now()
  114. code: res.code,
  115. sign: md5('login' + getApp().globalData.globalTimestamp),
  116. // invited:'invited'
  117. },
  118. success: res => {
  119. // 通过openid发起会员登录
  120. getApp().globalData.user_id = res.data.msg.id;
  121. getApp().globalData.open_id = res.data.msg.openid;
  122. getApp().globalData.isAuth = res.data.msg.isauth === '0';
  123. getApp().globalData.user_name = res.data.msg.name;
  124. getApp().globalData.user_headUrl = res.data.msg.headimg;
  125. getApp().globalData.times = res.data.msg.times;
  126. getApp().globalData.total_times = res.data.msg.total_times;
  127. that.getHistory();
  128. }
  129. });
  130. },
  131. getNowTime() {
  132. let time = new Date();
  133. let y = time.getFullYear();
  134. let m = time.getMonth() + 1;
  135. let d = time.getDate();
  136. let h = time.getHours();
  137. let i = time.getMinutes();
  138. i = i > 10 ? i : '0' + i;
  139. this.nowTime = y + "年" + m + "月" + d + "日" + " " + h + ":" + i
  140. },
  141. getEquipmentHeight() {
  142. const height = uni.getSystemInfoSync().windowHeight;
  143. this.nowHeight = height + 'px';
  144. getApp().globalData.glbalHeight = this.nowHeight;
  145. this.style.pageHeight = height;
  146. this.style.contentViewHeight = height - uni.getSystemInfoSync().screenWidth / 750 * (100); //像素 因为给出的是像素高度 然后我们用的是upx 所以换算一下
  147. },
  148. scrollToBottom() {
  149. let that = this;
  150. let query = uni.createSelectorQuery();
  151. query.selectAll('.m-item').boundingClientRect();
  152. query.select('#scrollview').boundingClientRect();
  153. query.exec((res) => {
  154. that.style.mitemHeight = 0;
  155. res[0].forEach((rect) => that.style.mitemHeight = that.style.mitemHeight + rect.height + 40) //获取所有内部子元素的高度
  156. // 因为vue的虚拟DOM 每次生成的新消息都是之前的,所以采用异步setTimeout 主要就是添加了这红字
  157. that.scrollTop = that.style.mitemHeight - that.style.contentViewHeight
  158. // setTimeout(() => {
  159. // if (that.style.mitemHeight > (that.style.contentViewHeight - 100)) { //判断子元素高度是否大于显示高度
  160. // that.scrollTop = that.style.mitemHeight - that.style.contentViewHeight //用子元素的高度减去显示的高度就获益获得序言滚动的高度
  161. // }
  162. // }, 100)
  163. })
  164. },
  165. getHistory() {
  166. let that = this;
  167. uni.request({
  168. url: getApp().globalData.shareUrl, //需要设置为全局
  169. method: 'POST',
  170. header: {
  171. 'content-type': 'application/x-www-form-urlencoded'
  172. },
  173. data: {
  174. method: 'question_list',
  175. timestamp: getApp().globalData.globalTimestamp, //Date.now()
  176. uid: getApp().globalData.user_id,
  177. sign: md5('question_list' + getApp().globalData.globalTimestamp),
  178. page: page || 1,
  179. pageSize: 10,
  180. },
  181. success: res => {
  182. that.userHeadUrl = getApp().globalData.user_headUrl;
  183. if(page === 1){
  184. that.scrollRequestEnable = true;
  185. that.talkList = ((res.data.msg).reverse());
  186. console.log(1,that.talkList)
  187. setTimeout(()=>{
  188. that.scrollToBottom()
  189. },100)
  190. }else if (page > 1 && res.data.msg.length === that.pageSize) {
  191. that.scrollRequestEnable = true;
  192. that.talkList.unshift(...((res.data.msg).reverse()));
  193. }else if (page > 1 && (res.data.msg.length > 0) && (res.data.msg.length < that.pageSize)){
  194. that.scrollRequestEnable = true;
  195. that.talkList.unshift(...((res.data.msg).reverse()));
  196. }else if (page > 1 && res.data.msg.length == 0){
  197. that.scrollRequestEnable = false;
  198. }
  199. }
  200. });
  201. },
  202. goUserSelf() {
  203. uni.navigateTo({
  204. url: '../selfInfo/selfInfo'
  205. })
  206. },
  207. sendMsgRequest(msg) {
  208. let that = this;
  209. uni.request({
  210. url: getApp().globalData.shareUrl, //需要设置为全局
  211. method: 'POST',
  212. header: {
  213. 'content-type': 'application/x-www-form-urlencoded'
  214. },
  215. data: {
  216. method: 'question',
  217. timestamp: getApp().globalData.globalTimestamp, //Date.now()
  218. uid: getApp().globalData.user_id,
  219. sign: md5('question' + getApp().globalData.globalTimestamp),
  220. content: msg
  221. },
  222. success: res => {
  223. this.inputInfo = '';
  224. that.getHistory();
  225. }
  226. });
  227. },
  228. sendInputInfo() {
  229. if (!this.inputInfo) {
  230. uni.showToast({
  231. title: '请输入股票代码',
  232. icon: 'none'
  233. });
  234. } else {
  235. page = 1;
  236. this.sendMsgRequest(this.inputInfo)
  237. }
  238. },
  239. // 滚动至底部触发的事件
  240. lower() {
  241. if (this.scrollRequestEnable) {
  242. // 允许滚动时,触底page加一,重新请求数据
  243. page++;
  244. this.getHistory();
  245. } else {
  246. // 不允许滚动时,只显示"到底了"提示
  247. // this.showBottem = true
  248. console.log('noData')
  249. }
  250. },
  251. getInputFocus(e){
  252. //this.isShowKeyBoard = e.detail.height
  253. },
  254. getInputBlur(){
  255. //this.isShowKeyBoard = 0
  256. },
  257. },
  258. }
  259. </script>
  260. <style>
  261. .content {
  262. text-align: center;
  263. }
  264. .chat-box {
  265. background: #f4f5f7;
  266. padding-top: 3%;
  267. /* padding-bottom: 100upx; */
  268. }
  269. .tips-box {
  270. background: #D5D5DA;
  271. font-size: 28upx;
  272. color: #fff;
  273. border-radius: 30upx;
  274. width: 50%;
  275. margin: 0 auto;
  276. height: 50rpx;
  277. line-height: 50rpx
  278. }
  279. .tips-title {
  280. width: 70%;
  281. margin-top: 5%;
  282. font-size: 30rpx;
  283. height: 70rpx;
  284. line-height: 70rpx
  285. }
  286. .send-box {
  287. width: 100%;
  288. height: 90rpx;
  289. position: fixed;
  290. bottom: 0;
  291. background: #F4F0ED;
  292. display: flex;
  293. align-items: center;
  294. }
  295. .talk-box {
  296. display: flex;
  297. justify-content: flex-start;
  298. align-items: center;
  299. margin-top: 3%;
  300. }
  301. .talk-box-end {
  302. justify-content: flex-end;
  303. }
  304. .talk-head-box {
  305. width: 80rpx;
  306. height: 80rpx;
  307. border-radius: 30rpx;
  308. margin-left: 2%;
  309. margin-right: 2%;
  310. }
  311. .talk-head {
  312. width: 100%;
  313. height: 100%;
  314. border-radius: 50%;
  315. }
  316. .talk-content {
  317. padding: 2%;
  318. background: #fff;
  319. /* height:50rpx;
  320. line-height: 50rpx; */
  321. font-size: 28rpx;
  322. border-top-right-radius: 20rpx;
  323. border-bottom-left-radius: 20rpx;
  324. border-bottom-right-radius: 20rpx;
  325. text-align: left;
  326. max-width: 70%;
  327. }
  328. .enter-box {
  329. width: 78%;
  330. height: 70rpx;
  331. margin-left: 5px;
  332. background: #fff;
  333. border-radius: 1%;
  334. text-align: left;
  335. }
  336. .submit-message {
  337. width: 18%;
  338. height: 70rpx;
  339. font-size: 28rpx;
  340. line-height: 70rpx;
  341. color: #fff;
  342. background-color: #0A98D5 !important;
  343. }
  344. .logo {
  345. height: 200upx;
  346. width: 200upx;
  347. margin-top: 200upx;
  348. margin-left: auto;
  349. margin-right: auto;
  350. margin-bottom: 50upx;
  351. }
  352. .text-area {
  353. display: flex;
  354. justify-content: center;
  355. }
  356. .title {
  357. font-size: 36upx;
  358. color: #8f8f94;
  359. }
  360. .uniFab{
  361. width:98px;
  362. height:36px;
  363. background:rgba(231,247,236,1);
  364. box-shadow:-6px 5px 74px 0px rgba(60,188,99,0.08);
  365. border-radius:100px 0px 0px 100px;
  366. right: 0upx;
  367. position: fixed;
  368. z-index: 9999;
  369. top: 50%;
  370. display: flex;
  371. justify-content: center;
  372. align-items: center;
  373. }
  374. .uniFab text{
  375. width:64px;
  376. font-size:16px;
  377. font-family:PingFangSC;
  378. font-weight:600;
  379. color:rgba(60,188,99,1);
  380. text-shadow:0px 1px 2px rgba(12,39,20,0.2);
  381. }
  382. </style>