index.vue 18 KB

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