fa-array-download.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <template>
  2. <view class="fa-array-download">
  3. <view class="u-flex">
  4. <view class="u-flex-2"><view class="">来源</view></view>
  5. <view class="u-flex-7 u-p-l-10"><view class="">地址</view></view>
  6. <view class="u-flex-4 u-p-l-10"><view class="">密码</view></view>
  7. </view>
  8. <view class="u-flex u-m-t-15" v-for="(item, index) in list" :key="index">
  9. <view class="u-flex-2"><u-input v-model="item.name" :trim="trim" placeholder="来源" :border="border" :clearable="false" /></view>
  10. <view class="u-flex-6 u-m-l-10 u-m-r-10 "><u-input v-model="item.url" placeholder="请输入地址" :trim="trim" :border="border" /></view>
  11. <view class="u-p-l-10 u-p-r-10 u-m-r-10 u-text-center close" @click="uploadFile(index)">
  12. <u-icon name="arrow-upward" color="#ffffff" size="30"></u-icon>
  13. </view>
  14. <view class="u-flex-3 u-m-r-10 "><u-input placeholder="密码" v-model="item.password" :trim="trim" :border="border" /></view>
  15. <view class="u-p-l-10 u-p-r-10 u-text-center close" @click="del(index)"><u-icon name="close" color="#ffffff" size="30"></u-icon></view>
  16. </view>
  17. <view class="u-text-right u-m-t-20">
  18. <u-button
  19. size="mini"
  20. type="primary"
  21. :custom-style="{ backgroundColor: lightColor, color: theme.bgColor, border: '1px solid ' + faBorderColor }"
  22. throttle-time="0"
  23. @click="add"
  24. >
  25. <u-icon name="plus" :color="theme.bgColor" size="25"></u-icon>
  26. <text class="u-m-l-5">追加</text>
  27. </u-button>
  28. </view>
  29. <fa-upload-file ref="file" @success="uploadSuccess"></fa-upload-file>
  30. </view>
  31. </template>
  32. <script>
  33. import Emitter from '@/uview-ui/libs/util/emitter.js';
  34. export default {
  35. name: 'fa-array-download',
  36. mixins: [Emitter],
  37. props: {
  38. contentList: {
  39. type: [Array, Object],
  40. default() {
  41. return [];
  42. }
  43. },
  44. showValue: {
  45. type: String,
  46. default() {
  47. return '';
  48. }
  49. }
  50. },
  51. watch: {
  52. contentList: {
  53. immediate: true,
  54. handler: function(val) {
  55. if (val) {
  56. let list = [];
  57. for (let i in val) {
  58. list.push({
  59. name: i,
  60. url: '',
  61. password: ''
  62. });
  63. }
  64. this.list = list;
  65. }
  66. }
  67. },
  68. list: {
  69. deep: true,
  70. handler: function(newValue) {
  71. let value = this.$u.test.empty(newValue)?'':JSON.stringify(newValue);
  72. this.$emit('input', value);
  73. setTimeout(() => {
  74. this.dispatch('u-form-item', 'on-form-blur', value);
  75. }, 50);
  76. }
  77. },
  78. showValue: {
  79. immediate: true,
  80. handler(val) {
  81. if (val) {
  82. this.list = JSON.parse(val);
  83. }
  84. }
  85. }
  86. },
  87. data() {
  88. return {
  89. border: true,
  90. trim: true,
  91. listIndex: 0,
  92. list: [
  93. {
  94. name: '',
  95. url: '',
  96. password: ''
  97. }
  98. ]
  99. };
  100. },
  101. methods: {
  102. add() {
  103. this.list.push({
  104. name: '',
  105. url: '',
  106. password: ''
  107. });
  108. },
  109. del(index) {
  110. this.list.splice(index, 1);
  111. },
  112. uploadFile(index) {
  113. this.listIndex = index;
  114. this.$refs.file.onUpload();
  115. },
  116. uploadSuccess(e) {
  117. this.$set(this.list[this.listIndex], 'url', e);
  118. },
  119. getData() {
  120. return this.list;
  121. }
  122. }
  123. };
  124. </script>
  125. <style lang="scss" scoped>
  126. .fa-array-download{
  127. width: 100%;
  128. }
  129. .close {
  130. background: #2c3e50;
  131. border-radius: 10rpx;
  132. }
  133. </style>