common.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //* 实例化,提供基础服务
  2. let mixins = [];
  3. if (typeof mixin !== "undefined") {
  4. mixins.push(mixin);
  5. }
  6. if (typeof componentMixins !== "undefined") {
  7. mixins.push(componentMixins);
  8. }
  9. const PanelForm = {
  10. template: `<el-form v-bind="$attrs"><slot/></el-form>`,
  11. };
  12. const PanelComponent = {
  13. template: `
  14. <div class="vue-main" :style="{ backgroundColor:backgroundColor,padding:padding }"><slot/></div>
  15. `,
  16. props: {
  17. backgroundColor: {
  18. type: String,
  19. default: "white"
  20. },
  21. padding: {
  22. type: String,
  23. default: "20px"
  24. }
  25. }
  26. };
  27. const PanelTitle = {
  28. template: `
  29. <div class="vue-main-title">
  30. <div class="vue-main-title-left"></div>
  31. <div class="vue-main-title-content">
  32. <slot />
  33. <span class="vue-main-title-sub"><slot name="sub"/></span>
  34. </div>
  35. <div class="vue-main-title-button"><slot name="right" /></div>
  36. </div>
  37. `,
  38. };
  39. const PageFixedContainer = {
  40. template: `
  41. <div class="vue-page">
  42. <slot />
  43. </div>
  44. `,
  45. };
  46. const FormItemPrompt = {
  47. props: {
  48. color: {
  49. type: String,
  50. default: "#999",
  51. },
  52. size: {
  53. type: String,
  54. default: "12px",
  55. },
  56. },
  57. template: `
  58. <div class="d-prompt" :style="{ color,fontSize:size }"><slot/></div>
  59. `,
  60. };
  61. new Vue({
  62. el: "#app",
  63. delimiters: ["[[", "]]"],
  64. mixins,
  65. data() {
  66. return {
  67. timeRangeTypes: [{
  68. text: "日",
  69. key: "day"
  70. }, {
  71. text: "周",
  72. key: "week"
  73. }, {
  74. text: "月",
  75. key: "month"
  76. }]
  77. }
  78. },
  79. methods: {
  80. fetchData(URL, requestParams) {
  81. return new Promise((resolve, reject) => {
  82. this.$http
  83. .post(URL, requestParams)
  84. .then(function (response) {
  85. return response.json();
  86. })
  87. .then(({ result, data, msg }) => {
  88. if (result == 0) {
  89. this.$message({
  90. message: msg,
  91. type: "error",
  92. });
  93. reject({ result, data, msg });
  94. }
  95. resolve(data);
  96. })
  97. .catch((err) => {
  98. reject(err);
  99. });
  100. });
  101. },
  102. randomNumber(baseNumber = 1000) {
  103. return Math.round(Math.random() * baseNumber);
  104. }
  105. },
  106. components: {
  107. PanelForm,
  108. PanelTitle,
  109. panel: PanelComponent,
  110. FormItemPrompt,
  111. PageFixedContainer,
  112. },
  113. });