index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  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="auth" v-if="!isAuth">
  7. <text>对不起,您还未登录!请</text>
  8. <button open-type="getUserInfo" @getuserinfo="getUserInfo">授权登录</button>
  9. </view>
  10. <!-- <view class="tips-box">
  11. {{nowTime}}
  12. </view> -->
  13. <!-- <view class="tips-box tips-title">
  14. 您好,智能投顾很高兴为您服务!
  15. </view> -->
  16. <!-- <view class="talk-box">
  17. <view class="talk-head-box">
  18. <image src="../../static/rabotHead.png" mode="" class="talk-head"></image>
  19. </view>
  20. <view class="talk-content">您好,欢迎您使用阿拉灯神丁。我可以给您提供股票投资建议,快来试试吧。</view>
  21. </view> -->
  22. <view v-for="chat in talkList" :key="chat.talkType" class="m-item">
  23. <view class="talk-box talk-box-end" v-show="chat.content">
  24. <view class="talk-reply">{{chat.content}}</view>
  25. <view class="talk-head-box">
  26. <image :src='userHeadUrl' mode="" class="talk-head" @click.stop='goUserSelf'></image>
  27. </view>
  28. </view>
  29. <view class="talk-box">
  30. <view class="talk-head-box">
  31. <image :src='rabotHeadImg' mode="" class="talk-head"></image>
  32. </view>
  33. <view class="talk-content">{{chat.reply}}<text class="goRechargeText" v-if='chat.isRecharge' @click.stop="goRecharge">去充值</text></view>
  34. </view>
  35. </view>
  36. </scroll-view>
  37. <view class="send-box" :style="{ 'padding-bottom' : isShowKeyBoard + 'px'}">
  38. <input type="text" class="enter-box" v-model="inputInfo" :adjust-position="true"
  39. :style="{'width':inputWidth}" confirm-hold='true' confirm-type='send' @confirm="sendInputInfo" />
  40. <!-- @input='isInputing' -->
  41. <!-- <button type="primary" class="submit-message" @click="sendInputInfo()" v-if='isShowSend'>发送</button> -->
  42. <image src="/static/setIcon.png" @click.stop='openModal()' v-if='isShowSetCenter'></image>
  43. </view>
  44. <!-- <drag-button :isDock="true" :existTabBar="true" @btnClick="goUserSelf" /> -->
  45. <uni-popup ref="popup" type="bottom">
  46. <view class="uni-share">
  47. <view class="uni-share-content">
  48. <view class="uni-share-content-box" @click.stop='goUserSelf' >
  49. <view class="uni-share-content-image">
  50. <image src="/static/icon/userSetIcon.png" class="image" />
  51. </view>
  52. <view class="uni-share-content-text">个人中心</view>
  53. </view>
  54. <view class="uni-share-content-box" @click.stop='goRecharge' >
  55. <view class="uni-share-content-image">
  56. <image src="/static/icon/recharge.png" class="image" />
  57. </view>
  58. <view class="uni-share-content-text">去充值</view>
  59. </view>
  60. </view>
  61. <view class="uni-share-btn" @click="cancelModal()">取消</view>
  62. </view>
  63. </uni-popup>
  64. </view>
  65. </template>
  66. <script>
  67. import uniPopup from "@/components/uni-popup/uni-popup.vue"
  68. var md5 = require("../../common/md5.js");
  69. var page = 1;
  70. export default {
  71. data() {
  72. return {
  73. isShowSend:false,
  74. isShowSetModal:false,
  75. isShowSetCenter:true,
  76. isShowRecharge:false,
  77. inputWidth:'80%',
  78. title: 'RABOT',
  79. nowTime: '',
  80. nowHeight: '622px',
  81. inputInfo: '',
  82. isShowKeyBoard:0,
  83. rabotHeadImg: "../../static/rabotHead.png",
  84. userHeadUrl: getApp().globalData.user_headUrl || '../../static/userDefault.png',
  85. talkList: [],
  86. scrollTopNav: 0, // 当linear为true的时候需要通过onpagescroll传递参数
  87. scrollMaxHeight: 200 ,//滑动的高度限制,超过这个高度即背景全部显示
  88. scrollTop:0,
  89. scrollRequestEnable: true,
  90. pageSize:10,
  91. style: {
  92. pageHeight: 0,
  93. contentViewHeight: 0,
  94. footViewHeight: 90,
  95. mitemHeight: 0
  96. },
  97. isAuth:true,
  98. }
  99. },
  100. components: {
  101. uniPopup
  102. },
  103. onPageScroll(e) {
  104. this.scrollTopNav = e.scrollTop;
  105. },
  106. onLoad() {
  107. this.userLogin();
  108. this.getEquipmentHeight();
  109. },
  110. onShow() {
  111. this.getNowTime();
  112. this.userHeadUrl = getApp().globalData.user_headUrl || '../../static/userDefault.png',
  113. this.isAuth = getApp().globalData.isAuth;
  114. },
  115. methods: {
  116. userLogin(){
  117. uni.showLoading({})
  118. uni.login({
  119. success: (res) => {
  120. this.getCodeRabot(res)
  121. }
  122. });
  123. },
  124. // 获取用户信息
  125. getUserInfo(e) {
  126. console.log(e);
  127. if (e.detail.errMsg == "getUserInfo:ok") {
  128. this.iv = e.detail.iv;
  129. this.encryptedData = e.detail.encryptedData;
  130. this.loginUserInfo()
  131. } else {
  132. console.log("用户信息授权失败");
  133. this.isShowAuthBtn = true;
  134. }
  135. },
  136. loginUserInfo(){
  137. let that = this;
  138. uni.request({
  139. url:getApp().globalData.shareUrl, //需要设置为全局
  140. method: 'POST',
  141. header: {
  142. 'content-type': 'application/x-www-form-urlencoded'
  143. },
  144. data: {
  145. method: 'auth',
  146. timestamp: getApp().globalData.globalTimestamp, //Date.now()
  147. uid:getApp().globalData.user_id,
  148. sign: md5('auth' + getApp().globalData.globalTimestamp),
  149. nickname:getApp().globalData.user_name,
  150. headimg:getApp().globalData.user_headUrl,
  151. iv:that.iv,
  152. session_key:that.session_key,
  153. encryptedData:that.encryptedData
  154. },
  155. success: res => {
  156. that.isAuth = true;
  157. getApp().globalData.user_id = res.data.msg.id;
  158. getApp().globalData.open_id = res.data.msg.openid;
  159. getApp().globalData.isAuth = that.isAuth;
  160. getApp().globalData.times = res.data.msg.times;
  161. getApp().globalData.total_times = res.data.msg.total_times;
  162. getApp().globalData.user_headUrl = res.data.msg.headimg;
  163. getApp().globalData.user_name = res.data.msg.name;
  164. that.userHeadUrl = res.data.msg.headimg || '../../static/userDefault.png';
  165. that.getHistory();
  166. }
  167. });
  168. },
  169. getCodeRabot(res){
  170. let that = this;
  171. uni.request({
  172. url:getApp().globalData.shareUrl, //需要设置为全局
  173. method: 'POST',
  174. header: {
  175. 'content-type': 'application/x-www-form-urlencoded'
  176. },
  177. data: {
  178. method: 'login',
  179. timestamp: getApp().globalData.globalTimestamp, //Date.now()
  180. code: res.code,
  181. sign: md5('login' + getApp().globalData.globalTimestamp),
  182. // invited:'invited'
  183. },
  184. success: res => {
  185. // 通过openid发起会员登录
  186. // getApp().globalData.user_id = res.data.msg.id;
  187. // getApp().globalData.open_id = res.data.msg.openid;
  188. // getApp().globalData.isAuth = res.data.msg.isauth === '0';
  189. // getApp().globalData.times = res.data.msg.times;
  190. // getApp().globalData.total_times = res.data.msg.total_times;
  191. // getApp().globalData.user_headUrl = res.data.msg.headimg;
  192. // getApp().globalData.user_name = res.data.msg.name;
  193. // that.userHeadUrl = res.data.msg.headimg || '../../static/userDefault.png';
  194. // that.getHistory();
  195. var isAuth = res.data.msg.isauth === 1;
  196. if(isAuth){
  197. getApp().globalData.user_id = res.data.msg.id;
  198. getApp().globalData.open_id = res.data.msg.openid;
  199. getApp().globalData.isAuth = isAuth;
  200. getApp().globalData.times = res.data.msg.times;
  201. getApp().globalData.total_times = res.data.msg.total_times;
  202. getApp().globalData.user_headUrl = res.data.msg.headimg;
  203. getApp().globalData.user_name = res.data.msg.name;
  204. that.userHeadUrl = res.data.msg.headimg || '../../static/userDefault.png';
  205. that.getHistory();
  206. }else{
  207. getApp().globalData.session_key = res.data.msg.session_key;
  208. that.isAuth = isAuth;
  209. wx.hideLoading();
  210. }
  211. }
  212. });
  213. },
  214. getNowTime() {
  215. let time = new Date();
  216. let y = time.getFullYear();
  217. let m = time.getMonth() + 1;
  218. let d = time.getDate();
  219. let h = time.getHours();
  220. let i = time.getMinutes();
  221. i = i > 10 ? i : '0' + i;
  222. this.nowTime = y + "年" + m + "月" + d + "日" + " " + h + ":" + i
  223. },
  224. getEquipmentHeight() {
  225. const height = uni.getSystemInfoSync().windowHeight;
  226. this.nowHeight = height + 'px';
  227. getApp().globalData.glbalHeight = this.nowHeight;
  228. this.style.pageHeight = height;
  229. this.style.contentViewHeight = height - uni.getSystemInfoSync().screenWidth / 750 * (100) -7; //像素 因为给出的是像素高度 然后我们用的是upx 所以换算一下
  230. },
  231. scrollToBottom() {
  232. let that = this;
  233. let query = uni.createSelectorQuery();
  234. query.selectAll('.m-item').boundingClientRect();
  235. query.select('#scrollview').boundingClientRect();
  236. query.exec((res) => {
  237. that.style.mitemHeight = 0;
  238. res[0].forEach((rect) => that.style.mitemHeight = that.style.mitemHeight + rect.height + 40) //获取所有内部子元素的高度
  239. // 因为vue的虚拟DOM 每次生成的新消息都是之前的,所以采用异步setTimeout 主要就是添加了这红字
  240. that.scrollTop = that.style.mitemHeight - that.style.contentViewHeight
  241. // setTimeout(() => {
  242. // if (that.style.mitemHeight > (that.style.contentViewHeight - 100)) { //判断子元素高度是否大于显示高度
  243. // that.scrollTop = that.style.mitemHeight - that.style.contentViewHeight //用子元素的高度减去显示的高度就获益获得序言滚动的高度
  244. // }
  245. // }, 100)
  246. })
  247. },
  248. getHistory(isShow) {
  249. let that = this;
  250. uni.request({
  251. url: getApp().globalData.shareUrl, //需要设置为全局
  252. method: 'POST',
  253. header: {
  254. 'content-type': 'application/x-www-form-urlencoded'
  255. },
  256. data: {
  257. method: 'question_list',
  258. timestamp: getApp().globalData.globalTimestamp, //Date.now()
  259. uid: getApp().globalData.user_id,
  260. sign: md5('question_list' + getApp().globalData.globalTimestamp),
  261. page: page || 1,
  262. pageSize: 10,
  263. },
  264. success: res => {
  265. uni.hideLoading()
  266. if(isShow){
  267. res.data.msg[0].isRecharge = 1
  268. }
  269. if(page === 1){
  270. that.scrollRequestEnable = true;
  271. that.talkList = ((res.data.msg).reverse());
  272. setTimeout(()=>{
  273. that.scrollToBottom()
  274. },100)
  275. }else if (page > 1 && res.data.msg.length === that.pageSize) {
  276. that.scrollRequestEnable = true;
  277. that.talkList.unshift(...((res.data.msg).reverse()));
  278. }else if (page > 1 && (res.data.msg.length > 0) && (res.data.msg.length < that.pageSize)){
  279. that.scrollRequestEnable = true;
  280. that.talkList.unshift(...((res.data.msg).reverse()));
  281. }else if (page > 1 && res.data.msg.length == 0){
  282. that.scrollRequestEnable = false;
  283. }
  284. }
  285. });
  286. },
  287. goUserSelf() {
  288. this.$refs.popup.close()
  289. uni.navigateTo({
  290. url: '../selfInfo/selfInfo'
  291. })
  292. },
  293. goRecharge() {
  294. this.$refs.popup.close()
  295. uni.navigateTo({
  296. url: '../selfInfo/payList/payList'
  297. })
  298. },
  299. sendMsgRequest(msg) {
  300. if(getApp().globalData.user_id=='') return false;
  301. let that = this;
  302. uni.request({
  303. url: getApp().globalData.shareUrl, //需要设置为全局
  304. method: 'POST',
  305. header: {
  306. 'content-type': 'application/x-www-form-urlencoded'
  307. },
  308. data: {
  309. method: 'question',
  310. timestamp: getApp().globalData.globalTimestamp, //Date.now()
  311. uid: getApp().globalData.user_id,
  312. sign: md5('question' + getApp().globalData.globalTimestamp),
  313. content: msg
  314. },
  315. success: res => {
  316. if(res.data.code === 100){
  317. that.isShowRecharge = true;
  318. that.inputInfo = '';
  319. that.getHistory('show');
  320. }else {
  321. that.inputInfo = '';
  322. that.getHistory();
  323. that.isShowRecharge = false
  324. }
  325. }
  326. });
  327. },
  328. sendInputInfo() {
  329. // this.inputWidth = '80%';
  330. // this.isShowSend = false;
  331. // this.isShowSetCenter = true;
  332. if (!this.inputInfo) {
  333. uni.showToast({
  334. title: '请输入股票代码',
  335. icon: 'none'
  336. });
  337. } else {
  338. page = 1;
  339. this.sendMsgRequest(this.inputInfo)
  340. }
  341. },
  342. isInputing(){
  343. if (this.inputInfo) {
  344. this.inputWidth = '72%';
  345. this.isShowSend = true;
  346. this.isShowSetCenter = false;
  347. } else {
  348. this.inputWidth = '80%';
  349. this.isShowSend = false;
  350. this.isShowSetCenter = true;
  351. }
  352. },
  353. // 滚动至底部触发的事件
  354. lower() {
  355. if (this.scrollRequestEnable) {
  356. // 允许滚动时,触底page加一,重新请求数据
  357. page++;
  358. this.getHistory();
  359. } else {
  360. // 不允许滚动时,只显示"到底了"提示
  361. // this.showBottem = true
  362. console.log('noData')
  363. }
  364. },
  365. getInputFocus(e){
  366. //this.isShowKeyBoard = e.detail.height
  367. },
  368. getInputBlur(){
  369. //this.isShowKeyBoard = 0
  370. },
  371. openModal(){
  372. // 需要在 popup 组件,指定 ref 为 popup
  373. this.$refs.popup.open();
  374. },
  375. cancelModal(){
  376. // 需要在 popup 组件,指定 ref 为 popup
  377. this.$refs.popup.close();
  378. }
  379. },
  380. onShareAppMessage(){
  381. }
  382. }
  383. </script>
  384. <style>
  385. .content {
  386. text-align: center;
  387. }
  388. .chat-box {
  389. background: #f4f5f7;
  390. padding-top: 3%;
  391. /* padding-bottom: 100upx; */
  392. }
  393. .tips-box {
  394. background: #D5D5DA;
  395. font-size: 28upx;
  396. color: #fff;
  397. border-radius: 30upx;
  398. width: 50%;
  399. margin: 0 auto;
  400. height: 50rpx;
  401. line-height: 50rpx
  402. }
  403. .tips-title {
  404. width: 70%;
  405. margin-top: 5%;
  406. font-size: 30rpx;
  407. height: 70rpx;
  408. line-height: 70rpx
  409. }
  410. .send-box {
  411. width: 100%;
  412. height: 90rpx;
  413. position: fixed;
  414. bottom: 0;
  415. background: #F4F0ED;
  416. display: flex;
  417. align-items: center;
  418. padding: 2upx;
  419. }
  420. .talk-box {
  421. display: flex;
  422. justify-content: flex-start;
  423. align-items: center;
  424. margin-top: 3%;
  425. }
  426. .talk-box-end {
  427. justify-content: flex-end;
  428. }
  429. .talk-head-box {
  430. width: 80rpx;
  431. height: 80rpx;
  432. border-radius: 30rpx;
  433. margin-left: 2%;
  434. margin-right: 2%;
  435. }
  436. .talk-head {
  437. width: 100%;
  438. height: 100%;
  439. border-radius: 50%;
  440. }
  441. .talk-content {
  442. padding: 2%;
  443. background: #fff;
  444. font-size: 28rpx;
  445. border-top-right-radius: 20rpx;
  446. border-bottom-left-radius: 20rpx;
  447. border-bottom-right-radius: 20rpx;
  448. text-align: left;
  449. max-width: 70%;
  450. }
  451. .talk-reply{
  452. padding: 2%;
  453. background: #9EEA6A;
  454. font-size: 28rpx;
  455. border-top-left-radius: 20rpx;
  456. border-bottom-left-radius: 20rpx;
  457. border-bottom-right-radius: 20rpx;
  458. text-align: left;
  459. max-width: 70%;
  460. }
  461. .goRechargeText {
  462. color:#0A98D5
  463. }
  464. .enter-box {
  465. height: 70rpx;
  466. background: #fff;
  467. border-radius: 1%;
  468. text-align: left;
  469. margin: 8px;
  470. margin-bottom: 10px;
  471. padding-left:8px;
  472. }
  473. .send-box image {
  474. width: 60rpx;
  475. height: 60rpx;
  476. margin-right: 10upx;
  477. margin-left: 10upx;
  478. }
  479. .submit-message {
  480. width: 18%;
  481. margin-right: 20upx;
  482. height: 70rpx;
  483. font-size: 28rpx;
  484. line-height: 70rpx;
  485. color: #fff;
  486. background-color: #0A98D5 !important;
  487. }
  488. .logo {
  489. height: 200upx;
  490. width: 200upx;
  491. margin-top: 200upx;
  492. margin-left: auto;
  493. margin-right: auto;
  494. margin-bottom: 50upx;
  495. }
  496. .text-area {
  497. display: flex;
  498. justify-content: center;
  499. }
  500. .title {
  501. font-size: 36upx;
  502. color: #8f8f94;
  503. }
  504. .uniFab{
  505. width:98px;
  506. height:36px;
  507. background:rgba(231,247,236,1);
  508. box-shadow:-6px 5px 74px 0px rgba(60,188,99,0.08);
  509. border-radius:100px 0px 0px 100px;
  510. right: 0upx;
  511. position: fixed;
  512. z-index: 9999;
  513. top: 50%;
  514. display: flex;
  515. justify-content: center;
  516. align-items: center;
  517. }
  518. .uniFab text{
  519. width:64px;
  520. font-size:16px;
  521. font-family:PingFangSC;
  522. font-weight:600;
  523. color:rgba(60,188,99,1);
  524. text-shadow:0px 1px 2px rgba(12,39,20,0.2);
  525. }
  526. .uni-share-content {
  527. display: flex;
  528. flex-wrap: wrap;
  529. padding: 15px;
  530. /* justify-content: center */
  531. }
  532. .uni-share-content-box {
  533. display: flex;
  534. flex-direction: column;
  535. align-items: center;
  536. width: 25%;
  537. box-sizing: border-box;
  538. }
  539. .uni-share-content-image {
  540. display: flex;
  541. justify-content: center;
  542. align-items: center;
  543. width: 60upx;
  544. height: 60upx;
  545. overflow: hidden;
  546. border-radius: 10upx;
  547. }
  548. .uni-share-content-image .image {
  549. width: 100%;
  550. height: 100%;
  551. }
  552. .uni-share-content-text {
  553. font-size: 26upx;
  554. color: #333;
  555. padding-top: 5px;
  556. padding-bottom: 10px;
  557. }
  558. .uni-share-btn {
  559. height: 90upx;
  560. line-height: 90upx;
  561. border-top: 1px #f5f5f5 solid;
  562. text-align: center;
  563. color: #666;
  564. font-size: 30rpx;
  565. }
  566. /* .placeHolder {
  567. padding:2px
  568. } */
  569. .auth{
  570. display: flex;
  571. flex-direction: row;
  572. font-size: 14px;
  573. justify-content: center;
  574. align-items: center;
  575. background-color: #eee;
  576. }
  577. .auth button{
  578. font-size: 14px;
  579. padding:0px;
  580. margin:0px;
  581. color:#007AFF;
  582. background-color: #eee;
  583. }
  584. .auth button:after{
  585. border: 0px;
  586. }
  587. </style>