index.vue 17 KB

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