App.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <template>
  2. <div id="app">
  3. <router-view />
  4. <!-- 语音播报 -->
  5. <iframe id="iframeDom" allow="autoplay" style="display:none" :src="src"></iframe>
  6. <audio class="audio" ref="audio" :src="url" controls autoplay hidden>
  7. </audio>
  8. </div>
  9. </template>
  10. <script>
  11. import { getSoundMsg } from "./api/setting.js";
  12. import bus from "./common/bus.js";
  13. export default {
  14. name: "App",
  15. data() {
  16. return {
  17. url: "../static/audio/test.mp3",
  18. audioList: [
  19. require("../static/audio/new-order.mp3"),
  20. require("../static/audio/lower-than.mp3"),
  21. require("../static/audio/missed-orders.mp3"),
  22. require("../static/audio/not-enough.mp3"),
  23. require("../static/audio/order-received.mp3"),
  24. require("../static/audio/rider-cancel.mp3"),
  25. require("../static/audio/user-go-cancel.mp3"),
  26. ],
  27. src: require("../static/audio/alone.mp3"),
  28. timer: null,
  29. openMsg: false,
  30. };
  31. },
  32. created() {
  33. console.log(1111);
  34. },
  35. mounted() {
  36. console.log(2222);
  37. bus.$on("closeGetSoundMsg", () => {
  38. console.log("进来准备关闭新订单提醒声音了");
  39. clearInterval(this.timer);
  40. this.timer = null;
  41. });
  42. bus.$on("openGetSoundMsg", () => {
  43. console.log("进来准备开启新订单提醒声音了");
  44. this.timer = setInterval(() => {
  45. this.getSoundMsg();
  46. }, 5000);
  47. });
  48. // 诱导用户出发点击动作,否则页面刷新后不会自动播放音频
  49. let userInfo = localStorage.getItem("userInfo");
  50. if (userInfo) {
  51. let nickname = JSON.parse(userInfo).nickname;
  52. this.$confirm(`当前登录账号:${nickname}`, "提示", {
  53. confirmButtonText: "确定",
  54. showCancelButton: false,
  55. type: "warning",
  56. }).then(() => {});
  57. }
  58. },
  59. beforeDestroy() {
  60. clearInterval(this.timer);
  61. this.timer = null;
  62. },
  63. methods: {
  64. getSoundMsg() {
  65. getSoundMsg().then((res) => {
  66. if (res.code === 200) {
  67. if (res.data) {
  68. let name = res.data.slice(0, res.data.indexOf("."));
  69. let url = this.audioList.filter((v) => {
  70. return v.includes(name);
  71. })[0];
  72. console.log("name", name);
  73. console.log("url", url);
  74. this.url = url + "?t=" + new Date().getTime();
  75. }
  76. } else {
  77. this.$message({
  78. type: "error",
  79. message: res.msg,
  80. });
  81. }
  82. });
  83. },
  84. },
  85. };
  86. </script>
  87. <style>
  88. body {
  89. margin: 0;
  90. padding: 0;
  91. }
  92. #app {
  93. font-family: "Avenir", Helvetica, Arial, sans-serif;
  94. -webkit-font-smoothing: antialiased;
  95. -moz-osx-font-smoothing: grayscale;
  96. margin: 0;
  97. padding: 0;
  98. }
  99. </style>