Commit 9e4a978f85fa94792895954faac2b4a929db7f15
1 parent
cc23ca2d
mp:解决 wx-msg 的 css 问题
Showing
5 changed files
with
239 additions
and
145 deletions
yudao-ui-admin/src/assets/images/wechat.png
0 → 100644
1.84 KB
yudao-ui-admin/src/views/mp/components/wx-msg/card.scss
0 → 100644
| 1 | +.avue-card{ | |
| 2 | + &__item{ | |
| 3 | + margin-bottom: 16px; | |
| 4 | + border: 1px solid #e8e8e8; | |
| 5 | + background-color: #fff; | |
| 6 | + box-sizing: border-box; | |
| 7 | + color: rgba(0,0,0,.65); | |
| 8 | + font-size: 14px; | |
| 9 | + font-variant: tabular-nums; | |
| 10 | + line-height: 1.5; | |
| 11 | + list-style: none; | |
| 12 | + font-feature-settings: "tnum"; | |
| 13 | + cursor: pointer; | |
| 14 | + height:200px; | |
| 15 | + &:hover{ | |
| 16 | + border-color: rgba(0,0,0,.09); | |
| 17 | + box-shadow: 0 2px 8px rgba(0,0,0,.09); | |
| 18 | + } | |
| 19 | + &--add{ | |
| 20 | + border:1px dashed #000; | |
| 21 | + width: 100%; | |
| 22 | + color: rgba(0,0,0,.45); | |
| 23 | + background-color: #fff; | |
| 24 | + border-color: #d9d9d9; | |
| 25 | + border-radius: 2px; | |
| 26 | + display: flex; | |
| 27 | + align-items: center; | |
| 28 | + justify-content: center; | |
| 29 | + font-size: 16px; | |
| 30 | + i{ | |
| 31 | + margin-right: 10px; | |
| 32 | + } | |
| 33 | + &:hover{ | |
| 34 | + color: #40a9ff; | |
| 35 | + background-color: #fff; | |
| 36 | + border-color: #40a9ff; | |
| 37 | + } | |
| 38 | + } | |
| 39 | + } | |
| 40 | + &__body{ | |
| 41 | + display: flex; | |
| 42 | + padding: 24px; | |
| 43 | + } | |
| 44 | + &__detail{ | |
| 45 | + flex:1 | |
| 46 | + } | |
| 47 | + &__avatar{ | |
| 48 | + width: 48px; | |
| 49 | + height: 48px; | |
| 50 | + border-radius: 48px; | |
| 51 | + overflow: hidden; | |
| 52 | + margin-right: 12px; | |
| 53 | + img{ | |
| 54 | + width: 100%; | |
| 55 | + height: 100%; | |
| 56 | + } | |
| 57 | + } | |
| 58 | + &__title{ | |
| 59 | + color: rgba(0,0,0,.85); | |
| 60 | + margin-bottom: 12px; | |
| 61 | + font-size: 16px; | |
| 62 | + &:hover{ | |
| 63 | + color:#1890ff; | |
| 64 | + } | |
| 65 | + } | |
| 66 | + &__info{ | |
| 67 | + color: rgba(0,0,0,.45); | |
| 68 | + display: -webkit-box; | |
| 69 | + -webkit-box-orient: vertical; | |
| 70 | + -webkit-line-clamp: 3; | |
| 71 | + overflow: hidden; | |
| 72 | + height: 64px; | |
| 73 | + } | |
| 74 | + &__menu{ | |
| 75 | + display: flex; | |
| 76 | + justify-content:space-around; | |
| 77 | + height: 50px; | |
| 78 | + background: #f7f9fa; | |
| 79 | + color: rgba(0,0,0,.45); | |
| 80 | + text-align: center; | |
| 81 | + line-height: 50px; | |
| 82 | + &:hover{ | |
| 83 | + color:#1890ff; | |
| 84 | + } | |
| 85 | + } | |
| 86 | +} | ... | ... |
yudao-ui-admin/src/views/mp/components/wx-msg/comment.scss
0 → 100644
| 1 | +/* 来自 https://github.com/nmxiaowei/avue/blob/master/styles/src/element-ui/comment.scss */ | |
| 2 | +.avue-comment{ | |
| 3 | + margin-bottom: 30px; | |
| 4 | + display: flex; | |
| 5 | + align-items: flex-start; | |
| 6 | + &--reverse{ | |
| 7 | + flex-direction:row-reverse; | |
| 8 | + .avue-comment__main{ | |
| 9 | + &:before,&:after{ | |
| 10 | + left: auto; | |
| 11 | + right: -8px; | |
| 12 | + border-width: 8px 0 8px 8px; | |
| 13 | + } | |
| 14 | + &:before{ | |
| 15 | + border-left-color: #dedede; | |
| 16 | + } | |
| 17 | + &:after{ | |
| 18 | + border-left-color: #f8f8f8; | |
| 19 | + margin-right: 1px; | |
| 20 | + margin-left: auto; | |
| 21 | + } | |
| 22 | + } | |
| 23 | + } | |
| 24 | + &__avatar{ | |
| 25 | + width: 48px; | |
| 26 | + height: 48px; | |
| 27 | + border-radius: 50%; | |
| 28 | + border: 1px solid transparent; | |
| 29 | + box-sizing: border-box; | |
| 30 | + vertical-align: middle; | |
| 31 | + } | |
| 32 | + &__header{ | |
| 33 | + padding: 5px 15px; | |
| 34 | + background: #f8f8f8; | |
| 35 | + border-bottom: 1px solid #eee; | |
| 36 | + display: flex; | |
| 37 | + align-items: center; | |
| 38 | + justify-content: space-between; | |
| 39 | + } | |
| 40 | + &__author{ | |
| 41 | + font-weight: 700; | |
| 42 | + font-size: 14px; | |
| 43 | + color: #999; | |
| 44 | + } | |
| 45 | + &__main{ | |
| 46 | + flex:1; | |
| 47 | + margin: 0 20px; | |
| 48 | + position: relative; | |
| 49 | + border: 1px solid #dedede; | |
| 50 | + border-radius: 2px; | |
| 51 | + &:before,&:after{ | |
| 52 | + position: absolute; | |
| 53 | + top: 10px; | |
| 54 | + left: -8px; | |
| 55 | + right: 100%; | |
| 56 | + width: 0; | |
| 57 | + height: 0; | |
| 58 | + display: block; | |
| 59 | + content: " "; | |
| 60 | + border-color: transparent; | |
| 61 | + border-style: solid solid outset; | |
| 62 | + border-width: 8px 8px 8px 0; | |
| 63 | + pointer-events: none; | |
| 64 | + } | |
| 65 | + &:before { | |
| 66 | + border-right-color: #dedede; | |
| 67 | + z-index: 1; | |
| 68 | + } | |
| 69 | + &:after{ | |
| 70 | + border-right-color: #f8f8f8; | |
| 71 | + margin-left: 1px; | |
| 72 | + z-index: 2; | |
| 73 | + } | |
| 74 | + } | |
| 75 | + &__body{ | |
| 76 | + padding: 15px; | |
| 77 | + overflow: hidden; | |
| 78 | + background: #fff; | |
| 79 | + font-family: Segoe UI,Lucida Grande,Helvetica,Arial,Microsoft YaHei,FreeSans,Arimo,Droid Sans,wenquanyi micro hei,Hiragino Sans GB,Hiragino Sans GB W3,FontAwesome,sans-serif;color: #333; | |
| 80 | + font-size: 14px; | |
| 81 | + } | |
| 82 | + blockquote{ | |
| 83 | + margin:0; | |
| 84 | + font-family: Georgia,Times New Roman,Times,Kai,Kaiti SC,KaiTi,BiauKai,FontAwesome,serif; | |
| 85 | + padding: 1px 0 1px 15px; | |
| 86 | + border-left: 4px solid #ddd; | |
| 87 | + } | |
| 88 | +} | ... | ... |
yudao-ui-admin/src/views/mp/components/wx-msg/main.vue
| 1 | 1 | <!-- |
| 2 | 2 | - Copyright (C) 2018-2019 |
| 3 | 3 | - All rights reserved, Designed By www.joolun.com |
| 4 | + 芋道源码: | |
| 5 | + ① 移除暂时用不到的 websocket | |
| 6 | + ② 代码优化,补充注释,提升阅读性 | |
| 4 | 7 | --> |
| 5 | 8 | <template> |
| 6 | - <div class="msg-main" v-loading="mainLoading"> | |
| 7 | - <div class="msg-div" :id="'msg-div'+nowStr"> | |
| 9 | + <div class="msg-main"> | |
| 10 | + <div class="msg-div" :id="'msg-div' + nowStr"> | |
| 8 | 11 | <!-- 加载更多 --> |
| 9 | 12 | <div v-loading="tableLoading"></div> |
| 10 | 13 | <div v-if="!tableLoading"> |
| ... | ... | @@ -15,9 +18,8 @@ |
| 15 | 18 | <div class="execution" v-for="item in tableData" :key='item.id'> |
| 16 | 19 | <div class="avue-comment" :class="item.sendFrom === 2 ? 'avue-comment--reverse' : ''"> |
| 17 | 20 | <div class="avatar-div"> |
| 18 | - <img :src="item.sendFrom === 1 ? item.headimgUrl : item.appLogo" class="avue-comment__avatar"> | |
| 19 | -<!-- <div class="avue-comment__author">{{item.sendFrom === 1 ? item.nickName : item.appName}}</div>--> | |
| 20 | - <div class="avue-comment__author">{{item.sendFrom === 1 ? '用户' : '公众号' }}</div> | |
| 21 | + <img :src="item.sendFrom === 1 ? user.avatar : mp.avatar" class="avue-comment__avatar"> | |
| 22 | + <div class="avue-comment__author">{{item.sendFrom === 1 ? user.nickname : mp.nickname }}</div> | |
| 21 | 23 | </div> |
| 22 | 24 | <div class="avue-comment__main"> |
| 23 | 25 | <div class="avue-comment__header"> |
| ... | ... | @@ -62,6 +64,7 @@ |
| 62 | 64 | </el-link> |
| 63 | 65 | <div class="avue-card__info" style="height: unset">{{item.description}}</div> |
| 64 | 66 | </div> |
| 67 | + <!-- TODO 芋艿:待完善 --> | |
| 65 | 68 | <!-- <div v-if="item.repType == 'location'">--> |
| 66 | 69 | <!-- <el-link type="primary" target="_blank" :href="'https://map.qq.com/?type=marker&isopeninfowin=1&markertype=1&pointx='+item.repLocationY+'&pointy='+item.repLocationX+'&name='+item.repContent+'&ref=joolun'">--> |
| 67 | 70 | <!-- <img :src="'https://apis.map.qq.com/ws/staticmap/v2/?zoom=10&markers=color:blue|label:A|'+item.repLocationX+','+item.repLocationY+'&key='+qqMapKey+'&size=250*180'">--> |
| ... | ... | @@ -118,28 +121,25 @@ |
| 118 | 121 | }, |
| 119 | 122 | data() { |
| 120 | 123 | return { |
| 121 | - nowStr: new Date().getTime(), | |
| 124 | + nowStr: new Date().getTime(), // 当前的时间戳,用于每次消息加载后,回到原位置;具体见 :id="'msg-div' + nowStr" 处 | |
| 122 | 125 | objData:{ |
| 123 | 126 | repType: 'text' |
| 124 | 127 | }, |
| 125 | - mainLoading:false, | |
| 126 | - sendLoading:false, | |
| 127 | - tableLoading:false, | |
| 128 | - loadMore: true, | |
| 128 | + sendLoading: false, // 发送消息是否加载中 | |
| 129 | + tableLoading: false, // 消息列表是否正在加载中 | |
| 130 | + loadMore: true, // 是否可以加载更多 | |
| 129 | 131 | tableData: [], // 消息列表 |
| 130 | 132 | page: { |
| 131 | - total: 0, // 总页数 | |
| 132 | 133 | pageNo: 1, // 当前页数 |
| 133 | 134 | pageSize: 14, // 每页显示多少条 |
| 134 | - ascs:[],//升序字段 | |
| 135 | - descs:'create_time'//降序字段 | |
| 136 | 135 | }, |
| 137 | - option: { | |
| 138 | - props: { | |
| 139 | - avatar: 'avatar', | |
| 140 | - author: 'author', | |
| 141 | - body: 'body' | |
| 142 | - } | |
| 136 | + user: { // 由于微信不再提供昵称,直接使用“用户”展示 | |
| 137 | + nickname: '用户', | |
| 138 | + avatar: require("@/assets/images/profile.jpg"), | |
| 139 | + }, | |
| 140 | + mp: { | |
| 141 | + nickname: '公众号', | |
| 142 | + avatar: require("@/assets/images/wechat.png"), | |
| 143 | 143 | } |
| 144 | 144 | } |
| 145 | 145 | }, |
| ... | ... | @@ -148,8 +148,8 @@ |
| 148 | 148 | }, |
| 149 | 149 | methods:{ |
| 150 | 150 | sendMsg(){ |
| 151 | - if(this.objData){ | |
| 152 | - if(this.objData.repType == 'news'){ | |
| 151 | + if (this.objData) { | |
| 152 | + if(this.objData.repType === 'news'){ | |
| 153 | 153 | this.objData.content.articles = [this.objData.content.articles[0]] |
| 154 | 154 | this.$message({ |
| 155 | 155 | showClose: true, |
| ... | ... | @@ -173,13 +173,7 @@ |
| 173 | 173 | }) |
| 174 | 174 | } |
| 175 | 175 | }, |
| 176 | - scrollToBottom: function () { | |
| 177 | - this.$nextTick(() => { | |
| 178 | - let div = document.getElementById('msg-div'+this.nowStr) | |
| 179 | - div.scrollTop = div.scrollHeight | |
| 180 | - }) | |
| 181 | - }, | |
| 182 | - loadingMore(){ | |
| 176 | + loadingMore() { | |
| 183 | 177 | this.page.pageNo++ |
| 184 | 178 | this.getPage(this.page) |
| 185 | 179 | }, |
| ... | ... | @@ -188,35 +182,35 @@ |
| 188 | 182 | getMessagePage(Object.assign({ |
| 189 | 183 | pageNo: page.pageNo, |
| 190 | 184 | pageSize: page.pageSize, |
| 191 | - descs:page.descs, | |
| 192 | - ascs: page.ascs, | |
| 193 | 185 | wxUserId: this.wxUserId |
| 194 | 186 | }, params)).then(response => { |
| 195 | - let msgDiv = document.getElementById('msg-div'+this.nowStr) | |
| 187 | + // 计算当前的滚动高度 | |
| 188 | + const msgDiv = document.getElementById('msg-div' + this.nowStr); | |
| 196 | 189 | let scrollHeight = 0 |
| 197 | 190 | if(msgDiv){ |
| 198 | 191 | scrollHeight = msgDiv.scrollHeight |
| 199 | 192 | } |
| 200 | - let data = response.data.list.reverse() | |
| 201 | - this.tableData = [...data , ...this.tableData] | |
| 202 | - this.page.total = response.data.total | |
| 193 | + | |
| 194 | + // 处理数据 | |
| 195 | + const data = response.data.list.reverse(); | |
| 196 | + this.tableData = [...data, ...this.tableData] | |
| 203 | 197 | this.tableLoading = false |
| 204 | - if(data.length < this.page.pageSize || data.length === 0){ | |
| 198 | + if (data.length < this.page.pageSize || data.length === 0){ | |
| 205 | 199 | this.loadMore = false |
| 206 | 200 | } |
| 207 | - if(this.page.pageNo == 1){//定位到消息底部 | |
| 208 | - this.scrollToBottom() | |
| 209 | - }else{ | |
| 210 | - if(data.length != 0){ | |
| 211 | - this.$nextTick(() => {//定位滚动条 | |
| 212 | - if(scrollHeight != 0){ | |
| 213 | - msgDiv.scrollTop = document.getElementById('msg-div'+this.nowStr).scrollHeight - scrollHeight - 100 | |
| 214 | - } | |
| 215 | - }) | |
| 216 | - } | |
| 217 | - } | |
| 218 | 201 | this.page.pageNo = page.pageNo |
| 219 | 202 | this.page.pageSize = page.pageSize |
| 203 | + | |
| 204 | + // 滚动到原来的位置 | |
| 205 | + if(this.page.pageNo === 1) { // 定位到消息底部 | |
| 206 | + this.scrollToBottom() | |
| 207 | + } else if (data.length !== 0) { // 定位滚动条 | |
| 208 | + this.$nextTick(() => { | |
| 209 | + if (scrollHeight !== 0){ | |
| 210 | + msgDiv.scrollTop = document.getElementById('msg-div'+this.nowStr).scrollHeight - scrollHeight - 100 | |
| 211 | + } | |
| 212 | + }) | |
| 213 | + } | |
| 220 | 214 | }) |
| 221 | 215 | }, |
| 222 | 216 | /** |
| ... | ... | @@ -224,120 +218,40 @@ |
| 224 | 218 | */ |
| 225 | 219 | refreshChange() { |
| 226 | 220 | this.getPage(this.page) |
| 227 | - } | |
| 221 | + }, | |
| 222 | + /** 定位到消息底部 */ | |
| 223 | + scrollToBottom: function () { | |
| 224 | + this.$nextTick(() => { | |
| 225 | + let div = document.getElementById('msg-div' + this.nowStr) | |
| 226 | + div.scrollTop = div.scrollHeight | |
| 227 | + }) | |
| 228 | + }, | |
| 228 | 229 | } |
| 229 | 230 | }; |
| 230 | 231 | </script> |
| 231 | 232 | <style lang="scss" scoped> |
| 232 | -/* 来自 https://github.com/nmxiaowei/avue/blob/master/styles/src/element-ui/comment.scss */ | |
| 233 | -/* 因为 joolun 实现依赖 avue 组件,该页面使用了 comment.scss */ | |
| 234 | -.avue-comment{ | |
| 235 | - margin-bottom: 30px; | |
| 236 | - display: flex; | |
| 237 | - align-items: flex-start; | |
| 238 | - &--reverse{ | |
| 239 | - flex-direction:row-reverse; | |
| 240 | - .avue-comment__main{ | |
| 241 | - &:before,&:after{ | |
| 242 | - left: auto; | |
| 243 | - right: -8px; | |
| 244 | - border-width: 8px 0 8px 8px; | |
| 245 | - } | |
| 246 | - &:before{ | |
| 247 | - border-left-color: #dedede; | |
| 248 | - } | |
| 249 | - &:after{ | |
| 250 | - border-left-color: #f8f8f8; | |
| 251 | - margin-right: 1px; | |
| 252 | - margin-left: auto; | |
| 253 | - } | |
| 254 | - } | |
| 255 | - } | |
| 256 | - &__avatar{ | |
| 257 | - width: 48px; | |
| 258 | - height: 48px; | |
| 259 | - border-radius: 50%; | |
| 260 | - border: 1px solid transparent; | |
| 261 | - box-sizing: border-box; | |
| 262 | - vertical-align: middle; | |
| 263 | - } | |
| 264 | - &__header{ | |
| 265 | - padding: 5px 15px; | |
| 266 | - background: #f8f8f8; | |
| 267 | - border-bottom: 1px solid #eee; | |
| 268 | - display: flex; | |
| 269 | - align-items: center; | |
| 270 | - justify-content: space-between; | |
| 271 | - } | |
| 272 | - &__author{ | |
| 273 | - font-weight: 700; | |
| 274 | - font-size: 14px; | |
| 275 | - color: #999; | |
| 276 | - } | |
| 277 | - &__main{ | |
| 278 | - flex:1; | |
| 279 | - margin: 0 20px; | |
| 280 | - position: relative; | |
| 281 | - border: 1px solid #dedede; | |
| 282 | - border-radius: 2px; | |
| 283 | - &:before,&:after{ | |
| 284 | - position: absolute; | |
| 285 | - top: 10px; | |
| 286 | - left: -8px; | |
| 287 | - right: 100%; | |
| 288 | - width: 0; | |
| 289 | - height: 0; | |
| 290 | - display: block; | |
| 291 | - content: " "; | |
| 292 | - border-color: transparent; | |
| 293 | - border-style: solid solid outset; | |
| 294 | - border-width: 8px 8px 8px 0; | |
| 295 | - pointer-events: none; | |
| 296 | - } | |
| 297 | - &:before { | |
| 298 | - border-right-color: #dedede; | |
| 299 | - z-index: 1; | |
| 300 | - } | |
| 301 | - &:after{ | |
| 302 | - border-right-color: #f8f8f8; | |
| 303 | - margin-left: 1px; | |
| 304 | - z-index: 2; | |
| 305 | - } | |
| 306 | - } | |
| 307 | - &__body{ | |
| 308 | - padding: 15px; | |
| 309 | - overflow: hidden; | |
| 310 | - background: #fff; | |
| 311 | - font-family: Segoe UI,Lucida Grande,Helvetica,Arial,Microsoft YaHei,FreeSans,Arimo,Droid Sans,wenquanyi micro hei,Hiragino Sans GB,Hiragino Sans GB W3,FontAwesome,sans-serif;color: #333; | |
| 312 | - font-size: 14px; | |
| 313 | - } | |
| 314 | - blockquote{ | |
| 315 | - margin:0; | |
| 316 | - font-family: Georgia,Times New Roman,Times,Kai,Kaiti SC,KaiTi,BiauKai,FontAwesome,serif; | |
| 317 | - padding: 1px 0 1px 15px; | |
| 318 | - border-left: 4px solid #ddd; | |
| 319 | - } | |
| 320 | -} | |
| 321 | -</style> | |
| 322 | -<style lang="scss" scoped> | |
| 323 | -.msg-main{ | |
| 233 | +/* 因为 joolun 实现依赖 avue 组件,该页面使用了 comment.scss、card.scc */ | |
| 234 | +@import './comment.scss'; | |
| 235 | +@import './card.scss'; | |
| 236 | + | |
| 237 | +.msg-main { | |
| 324 | 238 | margin-top: -30px; |
| 325 | 239 | padding: 10px; |
| 326 | 240 | } |
| 327 | -.msg-div{ | |
| 241 | +.msg-div { | |
| 328 | 242 | height: 50vh; |
| 329 | 243 | overflow: auto; |
| 330 | 244 | background-color: #eaeaea; |
| 331 | 245 | } |
| 332 | -.msg-send{ | |
| 246 | +.msg-send { | |
| 333 | 247 | padding: 10px; |
| 334 | 248 | } |
| 335 | -.avue-comment__main{ | |
| 249 | +.avue-comment__main { | |
| 336 | 250 | flex: unset!important; |
| 337 | 251 | border-radius: 5px!important; |
| 338 | 252 | margin: 0 8px!important; |
| 339 | 253 | } |
| 340 | -.avue-comment__header{ | |
| 254 | +.avue-comment__header { | |
| 341 | 255 | border-top-left-radius: 5px; |
| 342 | 256 | border-top-right-radius: 5px; |
| 343 | 257 | } |
| ... | ... | @@ -345,11 +259,11 @@ |
| 345 | 259 | border-bottom-right-radius: 5px; |
| 346 | 260 | border-bottom-left-radius: 5px; |
| 347 | 261 | } |
| 348 | -.avatar-div{ | |
| 262 | +.avatar-div { | |
| 349 | 263 | text-align: center; |
| 350 | 264 | width: 80px; |
| 351 | 265 | } |
| 352 | -.send-but{ | |
| 266 | +.send-but { | |
| 353 | 267 | float: right; |
| 354 | 268 | margin-top: 8px!important; |
| 355 | 269 | } | ... | ... |
yudao-ui-admin/src/views/mp/message/index.vue
| ... | ... | @@ -40,6 +40,12 @@ |
| 40 | 40 | </template> |
| 41 | 41 | </el-table-column> |
| 42 | 42 | <el-table-column label="消息类型" align="center" prop="type" width="80"/> |
| 43 | + <el-table-column label="发送方" align="center" prop="sendFrom" width="80"> | |
| 44 | + <template slot-scope="scope"> | |
| 45 | + <el-tag v-if="scope.row.sendFrom === 1" type="success">用户</el-tag> | |
| 46 | + <el-tag v-else type="info">公众号</el-tag> | |
| 47 | + </template> | |
| 48 | + </el-table-column> | |
| 43 | 49 | <el-table-column label="用户标识" align="center" prop="openid" width="300" /> |
| 44 | 50 | <!-- TODO 芋艿:发送/接收 --> |
| 45 | 51 | <el-table-column label="内容" prop="content"> | ... | ... |