CountrySelct.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <div class="country-select">
  3. <el-input
  4. v-model="productName"
  5. style="width: 240px"
  6. placeholder="第一步:输入你的产品名称,选择目标区域市场"
  7. />
  8. <span class="country-wrap">
  9. <el-dropdown ref="dropdown" trigger="contextmenu" popper-class="country-popper">
  10. <span class="country-wrap-item" @click="showCountryList" :title="countryInfo.name">
  11. <img :src="countryInfo.flag" />
  12. </span>
  13. <template #dropdown>
  14. <div class="custom-dropdown">
  15. <div class="custom-dropdown-filter">
  16. <el-input v-model="search" placeholder="Select Country">
  17. <template #prefix>
  18. <el-icon class="el-input__icon"><search /></el-icon>
  19. </template>
  20. </el-input>
  21. </div>
  22. <div class="custom-dropdown-list">
  23. <el-dropdown-menu>
  24. <el-dropdown-item
  25. v-for="item in countryList"
  26. :key="item.code"
  27. @click="() => selectCountry(item)"
  28. >
  29. <img :src="item.flag" />
  30. <span :class="{ 'country-name': true, active: countryInfo.code === item.code }">
  31. {{ item.code }}
  32. {{ '-' }}
  33. {{ item.name }}
  34. </span>
  35. </el-dropdown-item>
  36. </el-dropdown-menu>
  37. </div>
  38. </div>
  39. </template>
  40. </el-dropdown>
  41. </span>
  42. </div>
  43. </template>
  44. <script lang="ts" setup>
  45. import { reactive, ref } from 'vue';
  46. import countryData from '../assets/country.json';
  47. import type { DropdownInstance } from 'element-plus';
  48. interface countryItem {
  49. code: string;
  50. name: string;
  51. flag: any;
  52. }
  53. const images = import.meta.glob('@/assets/flags/4x3/*.svg', { eager: true, import: 'default' });
  54. const step = ref<number>(1);
  55. const productName = ref<string>('');
  56. const search = ref<string>('');
  57. const countryList: countryItem[] = countryData.map((item) => ({
  58. code: item.code.toUpperCase(),
  59. name: item.name,
  60. flag: images[`/src/assets/flags/4x3/${item.code}.svg`]
  61. }));
  62. const countryInfo = ref<countryItem>(countryList[0]);
  63. const dropdown = ref<DropdownInstance>();
  64. const selectCountry = (item: countryItem) => {
  65. countryInfo.value = item;
  66. };
  67. function showCountryList() {
  68. if (!dropdown.value) return;
  69. dropdown.value.handleOpen();
  70. }
  71. </script>
  72. <style lang="scss">
  73. .country-popper {
  74. .custom-dropdown {
  75. display: flex;
  76. flex-direction: column;
  77. width: 240px;
  78. height: 400px;
  79. padding: 5px;
  80. box-sizing: border-box;
  81. overflow: hidden;
  82. &-filter {
  83. height: 48px;
  84. .el-input__wrapper {
  85. height: 45px;
  86. }
  87. }
  88. &-list {
  89. flex: 1;
  90. overflow: auto;
  91. height: 100%;
  92. .el-dropdown-menu__item {
  93. padding: 10px;
  94. font-weight: 400;
  95. .country-name {
  96. color: #282e30;
  97. text-overflow: ellipsis;
  98. overflow: hidden;
  99. white-space: nowrap;
  100. &.active {
  101. color: #036eb8;
  102. }
  103. }
  104. img {
  105. width: 30px;
  106. margin: 0 6px;
  107. }
  108. }
  109. }
  110. }
  111. }
  112. </style>
  113. <style lang="scss" scoped>
  114. .country-select {
  115. display: flex;
  116. align-items: center;
  117. :deep(.el-input) {
  118. width: 25rem !important;
  119. height: 3rem !important;
  120. }
  121. :deep(.el-input__inner) {
  122. &::placeholder {
  123. font-size: 1rem !important;
  124. }
  125. }
  126. }
  127. .country-wrap {
  128. &-item {
  129. display: inline-flex;
  130. justify-content: center;
  131. align-items: center;
  132. width: 5.75rem;
  133. height: 4.25rem;
  134. background-color: #ffffff;
  135. margin-left: 0.625rem;
  136. cursor: pointer;
  137. img {
  138. width: 4.5rem;
  139. }
  140. }
  141. }
  142. </style>