123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <template>
- <view class="sfz" @click="chooseImage()" :style="{ border: fileName ? '' : '1px solid #eeeeee' }">
- <image :src="ip + fileName" mode="widthFix" v-if="fileName"></image>
- <view class="uploads" v-else>
- <view class="bw">
- <text class="icon"></text>
- <view class="text">选择图片</view>
- </view>
- </view>
- </view>
- </template>
- <script>
- export default {
- name: 'card',
- props: {
- value: {
- type: String
- },
- read: {
- type: Boolean,
- default: false
- }
- },
- data() {
- return {
- fileName: this.value,
- ip: this.http.ip
- };
- },
- watch: {
- value(newValue) {
- this.fileName = newValue;
- }
- },
- methods: {
- chooseImage() {
-
- uni.chooseImage({
- count: 1,
- sizeType: ['compressed'],
- success: res => {
- res.tempFilePaths.forEach(path => {
- uni.showLoading({ title: '正在上传图片', mask: true });
- uni.uploadFile({
- url: '/app/common/upload',
- filePath: path,
- name: 'file',
- header: { Authorization: this.getUser().token },
- success: res => {
- let data = JSON.parse(res.data);
- if (data.code == 200) {
- this.fileName = data.fileName;
- this.$emit('input', data.fileName);
- } else {
- uni.showModal({ content: data.msg, showCancel: false });
- }
- uni.hideLoading();
- },
- fail: res => {
- uni.hideLoading();
- uni.showModal({ content: '图片上传失败', showCancel: false });
- }
- });
- });
- }
- });
- },
-
- preview(item) {
- uni.previewImage({
- urls: [this.ip + item],
- current: this.ip + item,
- success: res => {}
- });
- },
- del(item) {
- this.value.splice(this.value.indexOf(item), 1);
- this.$emit('input', this.value);
- this.$forceUpdate();
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- .sfz {
- text-align: center;
- border-radius: 5px;
- margin-top: 10px;
- color: $fc;
- overflow: hidden;
- image {
- width: 100%;
- margin: 0 auto;
- border-radius: 5px;
- }
- .uploads {
- width: 100%;
- text-align: center;
- background-color: $bc1;
- .bw {
- padding: 20px;
- .icon {
- font-size: 50px;
- }
- .text {
- color: $fc;
- }
- }
- }
- }
- </style>
|