Notification.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. <template>
  2. <div>
  3. <div class="flex-container">
  4. <div class="flex-header">
  5. <Navbar
  6. title="消息"
  7. :is-go-back="true"
  8. />
  9. <div class="form-inline">
  10. <div class="form-group">
  11. <label>过滤条件</label>
  12. <input
  13. v-model="condition"
  14. autocomplete="off"
  15. class="form-control"
  16. placeholder="过滤条件"
  17. aria-describedby="basic-addon1"
  18. @keyup.enter="getDatas"
  19. />
  20. </div>
  21. <div class="form-group">
  22. <label for="exampleInputEmail2">选择用户组</label>
  23. <div class="input-group">
  24. <VueSimpleSuggest
  25. v-model="selectedUserName"
  26. :list="users"
  27. :filter-by-query="true"
  28. :styles="suggestStyles"
  29. :min-length="-1"
  30. display-attribute="name"
  31. value-attribute="id"
  32. @suggestion-click="selectUser"
  33. />
  34. </div>
  35. </div>
  36. <div class="form-group">
  37. <button
  38. type="button"
  39. class="btn btn-primary"
  40. @click="getDatas"
  41. >
  42. 查询
  43. </button>
  44. <button
  45. type="button"
  46. class="btn btn-success"
  47. @click="signAllRead"
  48. >
  49. 全部标记为已读
  50. </button>
  51. </div>
  52. </div>
  53. </div>
  54. <div class="flex-content">
  55. <!--<div class="notification"
  56. v-for="item in messages"
  57. @click="showSingleMessage(item)">
  58. <div class="time">
  59. {{item.timeInterval}}
  60. <div class="float-right">
  61. {{item.type}}
  62. </div>
  63. </div>
  64. <div>
  65. {{item.message}}
  66. </div>
  67. </div>-->
  68. <ul class="list-group">
  69. <template v-for="item in messages" :key="item.id">
  70. <li class="list-group-item" @click="showSingleMessage(item)">
  71. <span class="badge">{{ item.timeInterval }}</span>
  72. {{ item.message }}
  73. </li>
  74. </template>
  75. </ul>
  76. </div>
  77. <div class=" flex-footer">
  78. <div class="pull-left">
  79. <span>第{{ (pagination.current_page-1)*pagination.per_page+1 }}-{{ pagination.current_page*pagination.per_page }}条,共计{{ pagination.total }}条,每页显示</span>
  80. <PageSizeSelect @page-size-changed="gridSizeSelect" />
  81. <span>条</span>
  82. </div>
  83. <div class="pull-right">
  84. <VueBootstrapPagination
  85. v-if="pagination.last_page > 0"
  86. :pagination="pagination"
  87. :callback="getDatas"
  88. />
  89. </div>
  90. </div>
  91. </div>
  92. <div>
  93. <Loading v-if="loading" />
  94. </div>
  95. </div>
  96. </template>
  97. <script>
  98. import Common from '../common/Common.js';
  99. import { Notify, Uuid } from 'pc-component-v3';
  100. // import VueSimpleSuggest from 'vue-simple-suggest';
  101. export default {
  102. components: {
  103. },
  104. data: function () {
  105. return {
  106. 'loginInfo': '',
  107. 'messages': [],
  108. users: [],
  109. userId: undefined,
  110. selectedUserName: '',
  111. condition: '',
  112. selectedUserId: undefined,
  113. pagination: {
  114. total: 0,
  115. per_page: Common.pageSize, // required
  116. current_page: 1, // required
  117. last_page: 0, // required
  118. },
  119. suggestStyles: {
  120. 'defaultInput': 'form-control',
  121. },
  122. loading: false,
  123. };
  124. },
  125. mounted: function () {
  126. this.getLocalStorage();
  127. this.initUser();
  128. },
  129. methods: {
  130. // 获取localStorage
  131. getLocalStorage: function () {
  132. var storage = localStorage;
  133. if (!storage) {
  134. alert('浏览器不支持localstorage');
  135. } else {
  136. var json = storage.getItem('#LoginInfo');
  137. this.loginInfo = JSON.parse(json);
  138. this.userId = this.loginInfo.userId;
  139. this.getDatas();
  140. }
  141. },
  142. /**
  143. * 修改每页显示的数量
  144. * @param {Object} newPageSize
  145. */
  146. gridSizeSelect: function (newPageSize) {
  147. this.pagination.per_page = newPageSize;
  148. this.page = newPageSize;
  149. this.pagination.current_page = 1;
  150. // 刷新界面
  151. this.getDatas();
  152. },
  153. /**
  154. * 选择了用户
  155. */
  156. selectUser: function (user) {
  157. if (user) {
  158. this.selectedUserId = user.id;
  159. } else {
  160. this.selectedUserId = null;
  161. }
  162. },
  163. getDatas: function () {
  164. var _self = this;
  165. var queryParam = {
  166. range: {
  167. start: (_self.pagination.current_page - 1) * _self.pagination.per_page,
  168. length: _self.pagination.per_page,
  169. },
  170. condition: _self.condition,
  171. userId: _self.userId,
  172. id: _self.selectedUserId,
  173. };
  174. _self.loading=true;
  175. $.ajax({
  176. url: Common.getApiURL('messageQueueResource/queryByCondition'),
  177. type: 'post',
  178. dataType: 'json',
  179. contentType: 'application/json',
  180. data: JSON.stringify(queryParam),
  181. beforeSend: function (request) {
  182. Common.addTokenToRequest(request);
  183. },
  184. success: function (data) {
  185. _self.loading=false;
  186. if(data.errorCode != 0){
  187. Notify.error(_self.$t('lang.Notify.prompt'), data.errorMessage, false);
  188. return;
  189. }
  190. _self.showMessage(data.datas);
  191. _self.pagination.total = data.total;
  192. _self.pagination.last_page = Math.ceil(data.total / queryParam.range.length);
  193. },
  194. error: function (XMLHttpRequest, textStatus, errorThrown) {
  195. _self.loading=false;
  196. Common.processException(XMLHttpRequest, textStatus, errorThrown);
  197. },
  198. });
  199. },
  200. // 渲染消息
  201. showMessage: function (data) {
  202. var _self = this;
  203. // 清空数据
  204. _self.messages.splice(0, _self.messages.length);
  205. if (data == undefined || data.length == 0) {
  206. return;
  207. }
  208. for (var i = 0, len = data.length; i < len; i++) {
  209. _self.messages.push(data[i]);
  210. }
  211. },
  212. /**
  213. * 阅读某条消息
  214. * @param {Object} item
  215. * @return {void}
  216. */
  217. showSingleMessage: function (item) {
  218. var _self = this;
  219. _self.$router.push('/desktop/single-notification/' + item.id);
  220. },
  221. /**
  222. * 全部标记为已读
  223. */
  224. signAllRead: function () {
  225. var _self = this;
  226. _self.loading=true;
  227. $.ajax({
  228. url: Common.getApiURL('messageQueueResource/signAllRead'),
  229. type: 'get',
  230. dataType: 'json',
  231. data: {
  232. userId: _self.loginInfo.userId,
  233. },
  234. beforeSend: function (request) {
  235. Common.addTokenToRequest(request);
  236. },
  237. success: function (data) {
  238. if(data.errorCode != 0){
  239. Notify.error(_self.$t('lang.Notify.prompt'), data.errorMessage, false);
  240. return;
  241. }
  242. _self.loading=false;
  243. },
  244. error: function (XMLHttpRequest, textStatus, errorThrown) {
  245. _self.loading=false;
  246. Common.processException(XMLHttpRequest, textStatus, errorThrown);
  247. },
  248. });
  249. },
  250. /**
  251. * 初始化用户
  252. */
  253. initUser: function () {
  254. var _self = this;
  255. $.ajax({
  256. url: Common.getApiURL('groupResource/getGroupByClient'),
  257. dataType: 'json',
  258. type: 'get',
  259. beforeSend: function (request) {
  260. Common.addTokenToRequest(request);
  261. },
  262. success: function (data) {
  263. if (data != null) {
  264. data.unshift({
  265. name: '所有包含我的用户组',
  266. });
  267. _self.users = data;
  268. }
  269. },
  270. error: function (XMLHttpRequest, textStatus, errorThrown) {
  271. Common.processException(XMLHttpRequest, textStatus, errorThrown);
  272. },
  273. });
  274. },
  275. },
  276. };
  277. </script>
  278. <style>
  279. .notification-page {
  280. background-color: white;
  281. border: 1px solid #f1f1f1;
  282. border-radius: 5px;
  283. padding: 10px 15px;
  284. }
  285. .notification {
  286. border-bottom: 1px solid #eee;
  287. cursor: pointer;
  288. padding: 5px 10px;
  289. }
  290. .notification:hover {
  291. background-color: #f7f7f7;
  292. }
  293. .notification-inner {
  294. list-style: none;
  295. padding-left: 10px;
  296. }
  297. .image {
  298. width: 50px;
  299. height: 50px;
  300. border-radius: 50%;
  301. }
  302. .title {
  303. height: 50px;
  304. line-height: 50px;
  305. font-size: 22px;
  306. font-weight: block;
  307. padding-left: 15px;
  308. border-bottom: 1px solid #eee;
  309. }
  310. .time {
  311. color: #999;
  312. padding-left: 5px;
  313. }
  314. .float-right {
  315. float: right;
  316. }
  317. </style>
  318. <style scoped>
  319. .form-inline .form-group label {
  320. width: 80px;
  321. text-align: right;
  322. padding-right: 5px;
  323. }
  324. .form-inline .form-group input,
  325. .form-inline .form-group select {
  326. width: 200px;
  327. }
  328. </style>
  329. <style scoped>
  330. .flex-container {
  331. display: flex;
  332. /* 垂直*/
  333. flex-direction: column;
  334. width: 100%;
  335. /*视口被均分为100单位的vh 占据整个窗口,扣掉顶部topNav的距离后,计算得到container的高度*/
  336. height: calc(100vh - 85px);
  337. }
  338. .flex-header {
  339. height: 200px;
  340. /*放大缩小比例为0 */
  341. flex: 0 0 100px;
  342. }
  343. .flex-footer {
  344. margin-top: 0.8em;
  345. height: 35px;
  346. /*放大缩小比例为0 */
  347. flex: 0 0 35px;
  348. }
  349. .flex-content {
  350. margin-top: 0.8em;
  351. flex: 1;
  352. overflow: scroll;
  353. width: 100%;
  354. height: 0;
  355. }
  356. </style>