123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <!--证件照片上传(单张)-->
- <template>
- <view class="sfz" @click="chooseImage()">
- <image :src="ip + fileName" mode="widthFix" v-if="fileName"></image>
- <image :src="pic" mode="widthFix" v-else></image>
- </view>
- </template>
- <script>
- export default {
- name: 'card',
- props: {
- value: {
- type: String
- },
- pic: {
- 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, //默认9
- 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">
- .sfz {
- text-align: center;
- border-radius: 5px;
- margin-top: 10px;
- overflow: hidden;
- image {
- width: 100%;
- margin: 0 auto;
- border-radius: 5px;
- }
- }
- </style>
|