index.vue 18 KB

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