index.vue 13 KB

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