1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <!--证件照片上传(单张)-->
- <template>
- <view class="sfz" @click="chooseImage()">
- <image :src="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() {
- let url= this.http.ip+'/sp-admin/upload/image'
- //照片选择
- uni.chooseImage({
- count: 1, //默认9
- sizeType: ['compressed'], //可以指定是原图还是压缩图,默认二者都有
- success: res => {
- res.tempFilePaths.forEach(path => {
- uni.showLoading({ title: '正在上传图片', mask: true });
- uni.uploadFile({
- url: url,
- filePath: path,
- name: 'file',
- header: { Authorization: this.getUser().token },
- success: res => {
- let data = JSON.parse(res.data);
- console.log(data);
- if (data.code == 200) {
- this.fileName = data.data;
- this.$emit('input', data.data);
- } 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>
|