123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <template>
- <view class="upload">
- <view class="upload_1">
- <view class="button" v-if="list&&list.length<count" @tap="uplSuc()">
- <button style="background-color:#007AFF" type="primary" size="mini">选择文件</button>
- </view>
- <view class="list" v-for="(item,index) in list" :key="index">
- <text class="name" @click="toView(index,item)">{{item.name}} </text>
- <uni-icons class="del" type="close" size="20" color="#007AFF" @click="uplDel(index,item)"></uni-icons>
- </view>
- </view>
- </view>
- </template>
- <script>
- export default {
- props: {
- list: {
- type: Array,
- },
- name: {
- type: String,
- },
- count: {
- type: Number,
- default: 1
- }
- },
- data() {
- return {
- };
- },
- methods: {
- uplSuc() {
- const that = this;
- let serverFile = that.$config.serverFile;
- uni.chooseImage({
- count: 1,
- sizeType: ['original', 'compressed'],
- sourceType: ['album', 'camera'],
- success: async function(res) {
- let tempFile = JSON.parse(JSON.stringify(res.tempFilePaths));
- const arr = await that.$apifile(`/web/cxyy_applet/upload`, 'POST', tempFile[0],
- 'file');
- if (arr.errcode == '0') {
- that.$emit('uplSuc', {
- data: {
- id: arr.id,
- name: arr.name,
- uri: arr.uri,
- url: arr.uri
- },
- name: that.name
- })
- } else {
- uni.showToast({
- title: arr.errmsg,
- icon: 'none'
- });
- }
- }
- });
- },
- // 删除图片
- uplDel(index, e) {
- const that = this;
- that.$emit('uplDel', {
- data: {
- file: e,
- index: index
- },
- name: that.name
- })
- },
- // 图片预览
- toView(index, e) {
- const that = this;
- uni.previewImage({
- current: index,
- urls: [that.$config.serverFile + e.url]
- })
- },
- // 图片处理
- getUrl(e) {
- const that = this;
- if (e) return that.$config.serverFile + e
- },
- }
- }
- </script>
- <style lang="scss">
- .upload {
- padding: 0 2vw;
- .upload_1 {
- .list {
- display: flex;
- .name {
- font-size: 14px;
- color: #666;
- margin-right: 5px;
- word-break: break-all;
- word-wrap: break-word;
- }
- }
- }
- }
- </style>
|