quick.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. define(['vue', 'helper', 'store'], function (Vue, $h, api) {
  2. 'use strict';
  3. Vue.component('quick-menu', {
  4. data: function () {
  5. return {
  6. top: '50%',
  7. open: false,
  8. menuList: []
  9. };
  10. },
  11. created: function () {
  12. this.onReady();
  13. },
  14. methods: {
  15. onReady: function() {
  16. var that = this;
  17. api.baseGet($h.U({
  18. c: 'auth_api',
  19. a: 'suspensionButton'
  20. }), function(res) {
  21. var data = res.data.data;
  22. that.menuList = data;
  23. }, function(err) {
  24. console.error(err.data.msg);
  25. });
  26. },
  27. onMove: function(event) {
  28. var clientHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight,
  29. tithe = clientHeight / 10,
  30. min = tithe * 2,
  31. max = tithe * 8,
  32. top = 0;
  33. if (min >= event.touches[0].clientY) {
  34. top = clientHeight / 10 * 2;
  35. } else if (event.touches[0].clientY >= max) {
  36. top = clientHeight / 10 * 8;
  37. } else {
  38. top = event.touches[0].clientY;
  39. }
  40. this.top = top + 'px';
  41. }
  42. },
  43. template: '<div v-if="menuList.length" :style="{ top: top }" class="quick" @touchmove.stop.prevent="onMove">' +
  44. '<div v-show="open" class="menu">' +
  45. '<a v-for="item in menuList" :key="item.id" :href="item.url">' +
  46. '<img :src="item.icon" :alt="item.name">' +
  47. '</a>' +
  48. '</div>' +
  49. '<div class="quick-main" @click="open = !open">' +
  50. '<img :src="open ? \'/wap/first/zsff/images/quick_open.gif\' : \'/wap/first/zsff/images/quick_close.gif\'">' +
  51. '</div>' +
  52. '</div>'
  53. });
  54. });