file.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <div class="cl-menu-file">
  3. <el-row :gutter="10">
  4. <el-col :span="16">
  5. <el-select v-model="newValue" filterable clearable placeholder="请选择">
  6. <el-option
  7. v-for="(item, index) in list"
  8. :key="index"
  9. :label="item.value"
  10. :value="item.value"
  11. >
  12. </el-option>
  13. </el-select>
  14. </el-col>
  15. <el-col :span="8">
  16. <div class="cl-menu-file__module">
  17. <span class="label">模块</span>
  18. <el-select
  19. v-model="form.moduleName"
  20. placeholder="选择模块"
  21. clearable
  22. filterable
  23. @change="onModuleChange"
  24. >
  25. <el-option
  26. v-for="(item, index) in moduleViews"
  27. :key="index"
  28. :label="item.label"
  29. :value="item.moduleName"
  30. >
  31. </el-option>
  32. </el-select>
  33. </div>
  34. </el-col>
  35. </el-row>
  36. </div>
  37. </template>
  38. <script>
  39. import { mapGetters } from "vuex";
  40. import { isEmpty } from "cl-admin/utils";
  41. const files = require.context("@/", true, /^.\/views.*(vue|js)/).keys();
  42. export default {
  43. name: "cl-menu-file",
  44. props: {
  45. value: [String]
  46. },
  47. inject: ["form"],
  48. data() {
  49. return {
  50. newValue: "",
  51. list: []
  52. };
  53. },
  54. computed: {
  55. ...mapGetters(["moduleViews"])
  56. },
  57. watch: {
  58. value: {
  59. immediate: true,
  60. handler(val) {
  61. this.newValue = val || "";
  62. }
  63. },
  64. newValue(val) {
  65. this.$emit("input", val);
  66. }
  67. },
  68. created() {
  69. this.list = files
  70. .filter((e) => {
  71. return !e.includes("components");
  72. })
  73. .map((e) => {
  74. return {
  75. value: e.substr(2)
  76. };
  77. });
  78. },
  79. methods: {
  80. async onModuleChange(val) {
  81. const { label, keepAlive, icon, path, component } = this.moduleViews.find(
  82. (e) => e.moduleName == val
  83. );
  84. if (label) {
  85. this.form.name = label;
  86. }
  87. if (path) {
  88. this.form.router = path;
  89. }
  90. if (icon) {
  91. this.form.icon = icon;
  92. }
  93. if (component) {
  94. let c = await component();
  95. this.form.viewPath = c.default.__file;
  96. }
  97. this.form.keepAlive = isEmpty(keepAlive) ? true : keepAlive;
  98. }
  99. }
  100. };
  101. </script>
  102. <style lang="scss" scoped>
  103. .cl-menu-file {
  104. width: 100%;
  105. /deep/ .el-select {
  106. width: 100%;
  107. }
  108. &__module {
  109. display: inline-flex;
  110. .label {
  111. width: 40px;
  112. text-align: right;
  113. margin-right: 10px;
  114. }
  115. }
  116. }
  117. </style>