index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  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. @confirm='sendInputInfo' />
  36. <!-- <button type="primary" class="submit-message" @click="sendInputInfo()">发送</button> -->
  37. <image src="/static/setIcon.png" @click.stop='openModal()' ></image>
  38. </view>
  39. <!-- <drag-button :isDock="true" :existTabBar="true" @btnClick="goUserSelf" /> -->
  40. <uni-popup ref="popup" type="bottom">
  41. <view class="uni-share">
  42. <view class="uni-share-content">
  43. <view class="uni-share-content-box" @click.stop='goUserSelf' >
  44. <view class="uni-share-content-image">
  45. <image src="/static/icon/userSetIcon.png" class="image" />
  46. </view>
  47. <view class="uni-share-content-text">个人中心</view>
  48. </view>
  49. </view>
  50. <view class="uni-share-btn" @click="cancelModal()">取消</view>
  51. </view>
  52. </uni-popup>
  53. </view>
  54. </template>
  55. <script>
  56. import uniPopup from "@/components/uni-popup/uni-popup.vue"
  57. var md5 = require("../../common/md5.js");
  58. var page = 1;
  59. export default {
  60. data() {
  61. return {
  62. isShowSetModal:false,
  63. title: 'RABOT',
  64. nowTime: '',
  65. nowHeight: '622px',
  66. inputInfo: '',
  67. isShowKeyBoard:0,
  68. rabotHeadImg: "../../static/rabotHead.png",
  69. userHeadUrl: getApp().globalData.user_headUrl || '../../static/userDefault.png',
  70. talkList: [],
  71. scrollTopNav: 0, // 当linear为true的时候需要通过onpagescroll传递参数
  72. scrollMaxHeight: 200 ,//滑动的高度限制,超过这个高度即背景全部显示
  73. scrollTop:0,
  74. scrollRequestEnable: true,
  75. pageSize:10,
  76. style: {
  77. pageHeight: 0,
  78. contentViewHeight: 0,
  79. footViewHeight: 90,
  80. mitemHeight: 0
  81. },
  82. }
  83. },
  84. components: {
  85. uniPopup
  86. },
  87. onPageScroll(e) {
  88. this.scrollTopNav = e.scrollTop;
  89. },
  90. onLoad() {
  91. this.userLogin();
  92. this.getEquipmentHeight();
  93. },
  94. onShow() {
  95. this.getNowTime();
  96. },
  97. methods: {
  98. userLogin(){
  99. uni.login({
  100. success: (res) => {
  101. this.getCodeRabot(res)
  102. }
  103. });
  104. },
  105. getCodeRabot(res){
  106. let that = this;
  107. uni.request({
  108. url:getApp().globalData.shareUrl, //需要设置为全局
  109. method: 'POST',
  110. header: {
  111. 'content-type': 'application/x-www-form-urlencoded'
  112. },
  113. data: {
  114. method: 'login',
  115. timestamp: getApp().globalData.globalTimestamp, //Date.now()
  116. code: res.code,
  117. sign: md5('login' + getApp().globalData.globalTimestamp),
  118. // invited:'invited'
  119. },
  120. success: res => {
  121. // 通过openid发起会员登录
  122. getApp().globalData.user_id = res.data.msg.id;
  123. getApp().globalData.open_id = res.data.msg.openid;
  124. getApp().globalData.isAuth = res.data.msg.isauth === '0';
  125. getApp().globalData.user_name = res.data.msg.name;
  126. getApp().globalData.user_headUrl = res.data.msg.headimg;
  127. getApp().globalData.times = res.data.msg.times;
  128. getApp().globalData.total_times = res.data.msg.total_times;
  129. that.getHistory();
  130. }
  131. });
  132. },
  133. getNowTime() {
  134. let time = new Date();
  135. let y = time.getFullYear();
  136. let m = time.getMonth() + 1;
  137. let d = time.getDate();
  138. let h = time.getHours();
  139. let i = time.getMinutes();
  140. i = i > 10 ? i : '0' + i;
  141. this.nowTime = y + "年" + m + "月" + d + "日" + " " + h + ":" + i
  142. },
  143. getEquipmentHeight() {
  144. const height = uni.getSystemInfoSync().windowHeight;
  145. this.nowHeight = height + 'px';
  146. getApp().globalData.glbalHeight = this.nowHeight;
  147. this.style.pageHeight = height;
  148. this.style.contentViewHeight = height - uni.getSystemInfoSync().screenWidth / 750 * (100) -7; //像素 因为给出的是像素高度 然后我们用的是upx 所以换算一下
  149. },
  150. scrollToBottom() {
  151. let that = this;
  152. let query = uni.createSelectorQuery();
  153. query.selectAll('.m-item').boundingClientRect();
  154. query.select('#scrollview').boundingClientRect();
  155. query.exec((res) => {
  156. that.style.mitemHeight = 0;
  157. res[0].forEach((rect) => that.style.mitemHeight = that.style.mitemHeight + rect.height + 40) //获取所有内部子元素的高度
  158. // 因为vue的虚拟DOM 每次生成的新消息都是之前的,所以采用异步setTimeout 主要就是添加了这红字
  159. that.scrollTop = that.style.mitemHeight - that.style.contentViewHeight
  160. // setTimeout(() => {
  161. // if (that.style.mitemHeight > (that.style.contentViewHeight - 100)) { //判断子元素高度是否大于显示高度
  162. // that.scrollTop = that.style.mitemHeight - that.style.contentViewHeight //用子元素的高度减去显示的高度就获益获得序言滚动的高度
  163. // }
  164. // }, 100)
  165. })
  166. },
  167. getHistory() {
  168. let that = this;
  169. uni.request({
  170. url: getApp().globalData.shareUrl, //需要设置为全局
  171. method: 'POST',
  172. header: {
  173. 'content-type': 'application/x-www-form-urlencoded'
  174. },
  175. data: {
  176. method: 'question_list',
  177. timestamp: getApp().globalData.globalTimestamp, //Date.now()
  178. uid: getApp().globalData.user_id,
  179. sign: md5('question_list' + getApp().globalData.globalTimestamp),
  180. page: page || 1,
  181. pageSize: 10,
  182. },
  183. success: res => {
  184. that.userHeadUrl = getApp().globalData.user_headUrl;
  185. if(page === 1){
  186. that.scrollRequestEnable = true;
  187. that.talkList = ((res.data.msg).reverse());
  188. console.log(1,that.talkList)
  189. setTimeout(()=>{
  190. that.scrollToBottom()
  191. },100)
  192. }else if (page > 1 && res.data.msg.length === that.pageSize) {
  193. that.scrollRequestEnable = true;
  194. that.talkList.unshift(...((res.data.msg).reverse()));
  195. }else if (page > 1 && (res.data.msg.length > 0) && (res.data.msg.length < that.pageSize)){
  196. that.scrollRequestEnable = true;
  197. that.talkList.unshift(...((res.data.msg).reverse()));
  198. }else if (page > 1 && res.data.msg.length == 0){
  199. that.scrollRequestEnable = false;
  200. }
  201. }
  202. });
  203. },
  204. goUserSelf() {
  205. this.$refs.popup.close()
  206. uni.navigateTo({
  207. url: '../selfInfo/selfInfo'
  208. })
  209. },
  210. sendMsgRequest(msg) {
  211. let that = this;
  212. uni.request({
  213. url: getApp().globalData.shareUrl, //需要设置为全局
  214. method: 'POST',
  215. header: {
  216. 'content-type': 'application/x-www-form-urlencoded'
  217. },
  218. data: {
  219. method: 'question',
  220. timestamp: getApp().globalData.globalTimestamp, //Date.now()
  221. uid: getApp().globalData.user_id,
  222. sign: md5('question' + getApp().globalData.globalTimestamp),
  223. content: msg
  224. },
  225. success: res => {
  226. this.inputInfo = '';
  227. that.getHistory();
  228. }
  229. });
  230. },
  231. sendInputInfo() {
  232. if (!this.inputInfo) {
  233. uni.showToast({
  234. title: '请输入股票代码',
  235. icon: 'none'
  236. });
  237. } else {
  238. page = 1;
  239. this.sendMsgRequest(this.inputInfo)
  240. }
  241. },
  242. // 滚动至底部触发的事件
  243. lower() {
  244. if (this.scrollRequestEnable) {
  245. // 允许滚动时,触底page加一,重新请求数据
  246. page++;
  247. this.getHistory();
  248. } else {
  249. // 不允许滚动时,只显示"到底了"提示
  250. // this.showBottem = true
  251. console.log('noData')
  252. }
  253. },
  254. getInputFocus(e){
  255. //this.isShowKeyBoard = e.detail.height
  256. },
  257. getInputBlur(){
  258. //this.isShowKeyBoard = 0
  259. },
  260. openModal(){
  261. // 需要在 popup 组件,指定 ref 为 popup
  262. this.$refs.popup.open();
  263. },
  264. cancelModal(){
  265. // 需要在 popup 组件,指定 ref 为 popup
  266. this.$refs.popup.close();
  267. }
  268. },
  269. }
  270. </script>
  271. <style>
  272. .content {
  273. text-align: center;
  274. }
  275. .chat-box {
  276. background: #f4f5f7;
  277. padding-top: 3%;
  278. /* padding-bottom: 100upx; */
  279. }
  280. .tips-box {
  281. background: #D5D5DA;
  282. font-size: 28upx;
  283. color: #fff;
  284. border-radius: 30upx;
  285. width: 50%;
  286. margin: 0 auto;
  287. height: 50rpx;
  288. line-height: 50rpx
  289. }
  290. .tips-title {
  291. width: 70%;
  292. margin-top: 5%;
  293. font-size: 30rpx;
  294. height: 70rpx;
  295. line-height: 70rpx
  296. }
  297. .send-box {
  298. width: 100%;
  299. height: 90rpx;
  300. position: fixed;
  301. bottom: 0;
  302. background: #F4F0ED;
  303. display: flex;
  304. align-items: center;
  305. padding: 2upx;
  306. }
  307. .talk-box {
  308. display: flex;
  309. justify-content: flex-start;
  310. align-items: center;
  311. margin-top: 3%;
  312. }
  313. .talk-box-end {
  314. justify-content: flex-end;
  315. }
  316. .talk-head-box {
  317. width: 80rpx;
  318. height: 80rpx;
  319. border-radius: 30rpx;
  320. margin-left: 2%;
  321. margin-right: 2%;
  322. }
  323. .talk-head {
  324. width: 100%;
  325. height: 100%;
  326. border-radius: 50%;
  327. }
  328. .talk-content {
  329. padding: 2%;
  330. background: #fff;
  331. /* height:50rpx;
  332. line-height: 50rpx; */
  333. font-size: 28rpx;
  334. border-top-right-radius: 20rpx;
  335. border-bottom-left-radius: 20rpx;
  336. border-bottom-right-radius: 20rpx;
  337. text-align: left;
  338. max-width: 70%;
  339. }
  340. .enter-box {
  341. width: 85%;
  342. height: 70rpx;
  343. background: #fff;
  344. border-radius: 1%;
  345. text-align: left;
  346. margin: 8px
  347. }
  348. .send-box image {
  349. width: 60rpx;
  350. height: 60rpx;
  351. }
  352. .submit-message {
  353. width: 18%;
  354. height: 70rpx;
  355. font-size: 28rpx;
  356. line-height: 70rpx;
  357. color: #fff;
  358. background-color: #0A98D5 !important;
  359. }
  360. .logo {
  361. height: 200upx;
  362. width: 200upx;
  363. margin-top: 200upx;
  364. margin-left: auto;
  365. margin-right: auto;
  366. margin-bottom: 50upx;
  367. }
  368. .text-area {
  369. display: flex;
  370. justify-content: center;
  371. }
  372. .title {
  373. font-size: 36upx;
  374. color: #8f8f94;
  375. }
  376. .uniFab{
  377. width:98px;
  378. height:36px;
  379. background:rgba(231,247,236,1);
  380. box-shadow:-6px 5px 74px 0px rgba(60,188,99,0.08);
  381. border-radius:100px 0px 0px 100px;
  382. right: 0upx;
  383. position: fixed;
  384. z-index: 9999;
  385. top: 50%;
  386. display: flex;
  387. justify-content: center;
  388. align-items: center;
  389. }
  390. .uniFab text{
  391. width:64px;
  392. font-size:16px;
  393. font-family:PingFangSC;
  394. font-weight:600;
  395. color:rgba(60,188,99,1);
  396. text-shadow:0px 1px 2px rgba(12,39,20,0.2);
  397. }
  398. .uni-share-content {
  399. display: flex;
  400. flex-wrap: wrap;
  401. padding: 15px;
  402. /* justify-content: center */
  403. }
  404. .uni-share-content-box {
  405. display: flex;
  406. flex-direction: column;
  407. align-items: center;
  408. width: 25%;
  409. box-sizing: border-box;
  410. }
  411. .uni-share-content-image {
  412. display: flex;
  413. justify-content: center;
  414. align-items: center;
  415. width: 60upx;
  416. height: 60upx;
  417. overflow: hidden;
  418. border-radius: 10upx;
  419. }
  420. .uni-share-content-image .image {
  421. width: 100%;
  422. height: 100%;
  423. }
  424. .uni-share-content-text {
  425. font-size: 26upx;
  426. color: #333;
  427. padding-top: 5px;
  428. padding-bottom: 10px;
  429. }
  430. .uni-share-btn {
  431. height: 90upx;
  432. line-height: 90upx;
  433. border-top: 1px #f5f5f5 solid;
  434. text-align: center;
  435. color: #666;
  436. font-size: 30rpx;
  437. }
  438. </style>