index.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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="true" :scroll-top="scrollTop">
  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/logo.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">
  34. <input type="number" class="enter-box" v-model="inputInfo">
  35. <button type="primary" class="submit-message" @click="sendInputInfo()">发送</button>
  36. </view>
  37. </view>
  38. </template>
  39. <script>
  40. import navigationCustom from "../../components/struggler-navigationCustom/navigation-custom";
  41. var md5 = require("../../common/md5.js");
  42. export default {
  43. data() {
  44. return {
  45. title: 'RABOT',
  46. nowTime: '',
  47. nowHeight: '622px',
  48. inputInfo: '',
  49. rabotHeadImg: "../../static/logo.png",
  50. userHeadUrl: getApp().globalData.user_headUrl || '../../static/alienware.png',
  51. talkList: [],
  52. config: {
  53. title: "阿拉丁神灯", //title
  54. bgcolor: "#fff", //背景颜色
  55. fontcolor: "black", //文字颜色,默认白色
  56. type: 3, //type 1,3胶囊 2,4无胶囊模式
  57. transparent: false, //是否背景透明 默认白色
  58. linear: true, //是为开启下滑渐变
  59. share: true, //是否将主页按钮显示为分享按钮
  60. menuIcon: "../../static/icon/iconfont-user.png", //当type为3或者4的时候左边的icon文件位置,注意位置与当前页面不一样
  61. // menuText:"返回", 当type为3或4的时候icon右边的文字
  62. },
  63. scrollTopNav: 0, // 当linear为true的时候需要通过onpagescroll传递参数
  64. scrollMaxHeight: 200 ,//滑动的高度限制,超过这个高度即背景全部显示
  65. scrollTop:0,
  66. style: {
  67. pageHeight: 0,
  68. contentViewHeight: 0,
  69. footViewHeight: 90,
  70. mitemHeight: 0
  71. },
  72. }
  73. },
  74. components: {
  75. navigationCustom
  76. },
  77. onPageScroll(e) {
  78. this.scrollTopNav = e.scrollTop;
  79. },
  80. onLoad() {
  81. this.getEquipmentHeight();
  82. setTimeout(()=>{
  83. this.getHistory();
  84. },100)
  85. },
  86. onShow() {
  87. this.getNowTime();
  88. },
  89. methods: {
  90. getNowTime() {
  91. let time = new Date();
  92. let y = time.getFullYear();
  93. let m = time.getMonth() + 1;
  94. let d = time.getDate();
  95. let h = time.getHours();
  96. let i = time.getMinutes();
  97. i = i > 10 ? i : '0' + i;
  98. this.nowTime = y + "年" + m + "月" + d + "日" + " " + h + ":" + i
  99. },
  100. getEquipmentHeight() {
  101. const height = uni.getSystemInfoSync().windowHeight;
  102. this.nowHeight = height + 'px';
  103. getApp().globalData.glbalHeight = this.nowHeight;
  104. this.style.pageHeight = height;
  105. this.style.contentViewHeight = height - uni.getSystemInfoSync().screenWidth / 750 * (100) - 70; //像素 因为给出的是像素高度 然后我们用的是upx 所以换算一下
  106. },
  107. scrollToBottom() {
  108. let that = this;
  109. let query = uni.createSelectorQuery();
  110. query.selectAll('.m-item').boundingClientRect();
  111. query.select('#scrollview').boundingClientRect();
  112. query.exec((res) => {
  113. that.style.mitemHeight = 0;
  114. res[0].forEach((rect) => that.style.mitemHeight = that.style.mitemHeight + rect.height + 40) //获取所有内部子元素的高度
  115. // 因为vue的虚拟DOM 每次生成的新消息都是之前的,所以采用异步setTimeout 主要就是添加了这红字
  116. that.scrollTop = that.style.mitemHeight - that.style.contentViewHeight
  117. // setTimeout(() => {
  118. // if (that.style.mitemHeight > (that.style.contentViewHeight - 100)) { //判断子元素高度是否大于显示高度
  119. // that.scrollTop = that.style.mitemHeight - that.style.contentViewHeight //用子元素的高度减去显示的高度就获益获得序言滚动的高度
  120. // }
  121. // }, 100)
  122. })
  123. },
  124. getHistory() {
  125. let that = this;
  126. uni.request({
  127. url: getApp().globalData.shareUrl, //需要设置为全局
  128. method: 'POST',
  129. header: {
  130. 'content-type': 'application/x-www-form-urlencoded'
  131. },
  132. data: {
  133. method: 'question_list',
  134. timestamp: getApp().globalData.globalTimestamp, //Date.now()
  135. uid: getApp().globalData.user_id || '1',
  136. sign: md5('question_list' + getApp().globalData.globalTimestamp),
  137. page: 1,
  138. pageSize: 10,
  139. },
  140. success: res => {
  141. that.talkList = (res.data.msg).reverse();
  142. that.userHeadUrl = getApp().globalData.user_headUrl;
  143. setTimeout(()=>{
  144. that.scrollToBottom()
  145. },100)
  146. }
  147. });
  148. },
  149. customConduct() {
  150. uni.navigateTo({
  151. url: '../selfInfo/selfInfo'
  152. })
  153. },
  154. sendMsgRequest(msg) {
  155. let that = this;
  156. uni.request({
  157. url: getApp().globalData.shareUrl, //需要设置为全局
  158. method: 'POST',
  159. header: {
  160. 'content-type': 'application/x-www-form-urlencoded'
  161. },
  162. data: {
  163. method: 'question',
  164. timestamp: getApp().globalData.globalTimestamp, //Date.now()
  165. uid: getApp().globalData.user_id,
  166. sign: md5('question' + getApp().globalData.globalTimestamp),
  167. content: msg
  168. },
  169. success: res => {
  170. this.inputInfo = '';
  171. that.getHistory()
  172. }
  173. });
  174. },
  175. sendInputInfo() {
  176. if (!this.inputInfo) {
  177. uni.showToast({
  178. title: '请输入股票代码',
  179. icon: 'none'
  180. });
  181. } else {
  182. this.sendMsgRequest(this.inputInfo)
  183. }
  184. }
  185. },
  186. }
  187. </script>
  188. <style>
  189. .content {
  190. text-align: center;
  191. }
  192. .chat-box {
  193. background: #f4f5f7;
  194. padding-top: 3%;
  195. padding-bottom: 100upx;
  196. }
  197. .tips-box {
  198. background: #D5D5DA;
  199. font-size: 28upx;
  200. color: #fff;
  201. border-radius: 30upx;
  202. width: 50%;
  203. margin: 0 auto;
  204. height: 50rpx;
  205. line-height: 50rpx
  206. }
  207. .tips-title {
  208. width: 70%;
  209. margin-top: 5%;
  210. font-size: 30rpx;
  211. height: 70rpx;
  212. line-height: 70rpx
  213. }
  214. .send-box {
  215. width: 100%;
  216. height: 90rpx;
  217. position: fixed;
  218. bottom: 0;
  219. background: #F4F0ED;
  220. display: flex;
  221. align-items: center;
  222. }
  223. .talk-box {
  224. display: flex;
  225. justify-content: flex-start;
  226. align-items: center;
  227. margin-top: 3%;
  228. }
  229. .talk-box-end {
  230. justify-content: flex-end;
  231. }
  232. .talk-head-box {
  233. width: 80rpx;
  234. height: 80rpx;
  235. border-radius: 30rpx;
  236. margin-left: 2%;
  237. margin-right: 2%;
  238. }
  239. .talk-head {
  240. width: 100%;
  241. height: 100%;
  242. border-radius: 50%;
  243. }
  244. .talk-content {
  245. padding: 2%;
  246. background: #fff;
  247. /* height:50rpx;
  248. line-height: 50rpx; */
  249. font-size: 28rpx;
  250. border-top-right-radius: 20rpx;
  251. border-bottom-left-radius: 20rpx;
  252. border-bottom-right-radius: 20rpx;
  253. text-align: left;
  254. max-width: 70%;
  255. }
  256. .enter-box {
  257. width: 78%;
  258. height: 70rpx;
  259. margin-left: 5px;
  260. background: #fff;
  261. border-radius: 1%;
  262. text-align: left;
  263. }
  264. .submit-message {
  265. width: 18%;
  266. height: 70rpx;
  267. font-size: 28rpx;
  268. line-height: 70rpx;
  269. color: #fff;
  270. background-color: #0A98D5 !important;
  271. }
  272. .logo {
  273. height: 200upx;
  274. width: 200upx;
  275. margin-top: 200upx;
  276. margin-left: auto;
  277. margin-right: auto;
  278. margin-bottom: 50upx;
  279. }
  280. .text-area {
  281. display: flex;
  282. justify-content: center;
  283. }
  284. .title {
  285. font-size: 36upx;
  286. color: #8f8f94;
  287. }
  288. </style>