notification.blade.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <!DOCTYPE html>
  2. <html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <link rel="icon" href="{{asset('icon/faviconc.ico')}}" type="image/x-icon"/>
  7. <title>通知栏</title>
  8. <!-- CSRF Token -->
  9. <meta name="csrf-token" content="{{ csrf_token() }}">
  10. <link href="{{ mix('css/app.css') }}" rel="stylesheet">
  11. <style>
  12. html{
  13. height: 100%;
  14. width: 100%;
  15. }
  16. body{
  17. width: 100%;
  18. margin : 0 auto;
  19. }
  20. .b-container{
  21. background: RGB(245,250,245) !important;
  22. }
  23. li{
  24. cursor: pointer;
  25. }
  26. ul{
  27. max-height: 100%;
  28. max-width: 100%;
  29. overflow: auto;
  30. border: RGB(204, 204, 204) solid 1px;
  31. border-radius: 5px;
  32. }
  33. #msg{
  34. width:266px;
  35. position: fixed;
  36. z-index:999;
  37. top: 49%;
  38. margin-top:-80px;
  39. left:50%;
  40. margin-left:-133px;
  41. background:#fff;
  42. box-shadow:5px 5px 8px #999;
  43. font-size:17px;
  44. color:#666;
  45. border:1px solid #f8f8f8;
  46. text-align: center;
  47. line-height: 2rem;
  48. display:inline-block;
  49. padding-bottom:20px;
  50. border-radius:5px;
  51. }
  52. #msg_top {
  53. background: #f8f8f8;
  54. padding: 5px 15px 5px 20px;
  55. text-align: left;
  56. }
  57. #msg_top span{
  58. font-size:22px;
  59. float:right;
  60. cursor:pointer;
  61. }
  62. #msg_cont{
  63. padding:15px 20px 20px;
  64. text-align:left;
  65. }
  66. #msg_clear{
  67. background:#8fc31f;
  68. float:right;
  69. }
  70. #msg_success{
  71. background:#2a9055;
  72. float:right;
  73. }
  74. .msg_btn{
  75. display:inline-block;
  76. color:#fff;
  77. padding:1px 15px;
  78. border-radius:2px;
  79. margin-right:15px;
  80. cursor:pointer;
  81. }
  82. </style>
  83. </head>
  84. <body class="h-100">
  85. <div id="notification" class="w-100 h-100 b-container p-0 card">
  86. <div class="card-header">
  87. <label class="h3 text-center w-100">
  88. <b style="font-family:STHupo">@{{ count }}</b>
  89. <label class="text-secondary" style="font-family:STZhongsong">条未处理通知</label>
  90. </label>
  91. </div>
  92. <div class="card-body p-0">
  93. <ul class="list-group" id="scroll-list">
  94. <li class="list-group-item mt-3" v-for="info in infos" @click="toTarget(info)">
  95. <div class="row">
  96. <div class="col-7 row">
  97. <div class="col-3 pr-0 h5" v-if="info.delivered=='0'"><span class="badge badge-secondary">New</span></div>
  98. <div v-else class="col-1"></div>
  99. <div class="text-left text-overflow-replace font-weight-bold col-8 p-0">@{{ info.title }}</div>
  100. </div>
  101. <div class="text-right text-secondary col-5">@{{ info.created_at }}</div>
  102. </div>
  103. <div class="offset-2 mt-2 text-muted" v-html="info.message">
  104. </div>
  105. </li>
  106. </ul>
  107. </div>
  108. </div>
  109. </body>
  110. <script src="{{ mix('js/app.js') }}"></script>
  111. <script type="text/javascript">
  112. var audioPlay = false;
  113. //重绘弹窗样式
  114. function alert(e){
  115. $("body").append('<div id="msg"><div id="msg_top">设置<span class="msg_close">×</span></div><div id="msg_cont">'+e+
  116. '</div><div class="msg_close msg_btn" id="msg_clear">取消</div><div class="msg_close msg_btn" id="msg_success">确定</div></div>');
  117. $("#msg_clear").click(function (){
  118. $("#msg").remove();
  119. });
  120. $("#msg_success").click(function (){
  121. audioPlay = true;
  122. $("#msg").remove();
  123. });
  124. }
  125. alert("是否开启音频?");
  126. new Vue({
  127. el:"#notification",
  128. data:{
  129. infos:{!! $infos !!},
  130. loadSign:false,
  131. count: {!! $count !!},
  132. page:2,
  133. mark:{
  134. "0" : "/storage/audio.mp3",
  135. }
  136. },
  137. mounted(){
  138. if(this.infos.length===15)this.bindListen();
  139. $(document.body).append($('<audio id="audio" src="" autoplay></audio>'));
  140. if (Notification.permission!=='granted')Notification.requestPermission();
  141. this.initBroadcast();
  142. },
  143. methods: {
  144. bindListen(){
  145. $("#scroll-list").scroll(()=>{
  146. let element = $("#scroll-list");
  147. let scrollTop = element.scrollTop();
  148. let scrollHeight = element[0].scrollHeight;
  149. let height = element.height();
  150. if(scrollTop + height > scrollHeight-50){
  151. this.loadData();
  152. }
  153. });
  154. },
  155. initBroadcast() {
  156. initEcho();
  157. Echo.private('App.User.' + "{{\Illuminate\Support\Facades\Auth::id()}}")
  158. .notification((notification) => {
  159. this.count++;
  160. this.infos.unshift(notification);
  161. if (notification.mark==0)this._handleWorkOrder(notification);
  162. });
  163. },
  164. _handleWorkOrder(notification){
  165. this.playAudio(notification.mark);
  166. if(window.Notification ) {
  167. Notification.requestPermission(function(status) {
  168. let notify = new Notification('通知面板', { body: '有新工单',icon:"{{asset('icon/faviconc.ico')}}" });
  169. notify.onclick=function(){
  170. //如果通知消息被点击,通知窗口将被激活
  171. window.focus();
  172. notify.close();
  173. //打开对应的界面
  174. window.open('{{url('')}}'+'/'+notification.link);
  175. };
  176. });
  177. }
  178. },
  179. playAudio(mark){
  180. if (!audioPlay)return;
  181. let audio = document.getElementById('audio');
  182. audio.src = this.mark[mark];
  183. setTimeout(()=>{
  184. audio.play();
  185. },0);
  186. },
  187. toTarget(info = null){
  188. if (info.delivered==='0'){
  189. window.tempTip.postBasicRequest("{{url('notification/toTarget')}}",
  190. {id:info.no ? info.no : info.id},res=>{
  191. info.delivered = '1';
  192. this.count--;
  193. })
  194. }
  195. window.open('{{url('')}}'+'/'+info.link);
  196. },
  197. loadData(){
  198. if (this.loadSign)return;
  199. this.loadSign = true;
  200. let last = this.infos[this.infos.length-1];
  201. window.tempTip.postBasicRequest("{{url('notification/regular')}}",
  202. {id:last.no ? last.no : last.id,page:this.page},res=>{
  203. this.loadSign = false;
  204. this.page++;
  205. if (res)this.infos.push.apply(this.infos,res);
  206. if (!res || res.length<15)$("#scroll-list").unbind("scroll");
  207. })
  208. }
  209. }
  210. });
  211. </script>
  212. </html>