main.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * @Author: xvying 1615026511@qq.com
  3. * @Date: 2022-10-09 11:40:36
  4. * @LastEditors: xvying 1615026511@qq.com
  5. * @LastEditTime: 2022-11-21 13:14:52
  6. * @FilePath: /party/src/main.js
  7. * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  8. */
  9. import Vue from "vue";
  10. import "normalize.css/normalize.css"; // A modern alternative to CSS resets
  11. import "jquery";
  12. import ElementUI from "element-ui";
  13. import "element-ui/lib/theme-chalk/index.css";
  14. import locale from "element-ui/lib/locale/lang/en"; // lang i18n
  15. import "@/styles/index.scss"; // global css
  16. import App from "./App";
  17. import store from "./store";
  18. import router from "./router";
  19. import "@/icons"; // icon
  20. import "@/permission"; // permission control
  21. /**
  22. * If you don't want to use mock-server
  23. * you want to use MockJs for mock api
  24. * you can execute: mockXHR()
  25. *
  26. * Currently MockJs will be used in the production environment,
  27. * please remove it before going online ! ! !
  28. */
  29. //if (process.env.NODE_ENV === 'production') {
  30. //const { mockXHR } = require('../mock')
  31. //mockXHR()
  32. //}
  33. Vue.prototype.base_url =
  34. process.env.ENV === "development"
  35. ? "http://api.party.site.ximengnaikang.com" // 开发地址
  36. : process.env.ENV === "production"
  37. ? "http://api.party.demo.xmnk.cn" // 生产地址
  38. : "http://api.party.demo.xmnk.cn"; // 测试地址
  39. // set ElementUI lang to EN
  40. //Vue.use(ElementUI, { locale })
  41. // 如果想要中文版 element-ui,按如下方式声明
  42. Vue.use(ElementUI);
  43. Vue.config.productionTip = false;
  44. // 注册 EventBus
  45. Vue.prototype.$event = new Vue();
  46. // 注册全局自定义快速读取 excel `v-read-excel`
  47. Vue.directive("read-excel", {
  48. inserted: (el, { value }) => {
  49. const id = Date.now();
  50. const input = document.createElement("input");
  51. el["read-excel-id"] = id;
  52. input.id = id;
  53. input.type = "file";
  54. input.accept = ".xlsx, .xls";
  55. input.style.display = "none";
  56. document.body.appendChild(input);
  57. input.onchange = ({
  58. target: {
  59. files: [excel],
  60. },
  61. }) => {
  62. try {
  63. const XLSX = require("xlsx");
  64. const reader = new FileReader();
  65. reader.onload = async ({ target: { result } }) => {
  66. const workbook = XLSX.read(result, { type: "array" });
  67. value &&
  68. value(
  69. XLSX.utils.sheet_to_json(workbook.Sheets[workbook.SheetNames[0]])
  70. );
  71. };
  72. reader.readAsArrayBuffer(excel);
  73. } catch (e) {
  74. console.log(e);
  75. this.$message.error("上传文件失败,请刷新重试");
  76. }
  77. };
  78. el.addEventListener("click", () => {
  79. input.value = "";
  80. input.click();
  81. });
  82. },
  83. unbind: (el) => document.getElementById(el["read-excel-id"]).remove(),
  84. });
  85. new Vue({
  86. el: "#app",
  87. router,
  88. store,
  89. render: (h) => h(App),
  90. });