| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <template>
- <view class="upBox">
- <uni-file-picker
- limit="3"
- fileMediatype="image"
- file-extname="jpg,jpeg,png"
- @select="picSelect"
- @success="picSuccess"
- @fail="picFail"
- @delete="picDelete"
- title="最多选择3张图片">
- </uni-file-picker>
- </view>
- </template>
- <script>
- export default {
- name:"uploadFile",
- props: {
- module: {
- type: String,
- default: "",
- }
- },
- data() {
- return {
- attaments:[]
- };
- },
- methods: {
- //选择图片,上传
- picSelect(e){
- let that = this;
- const tempFilePaths = e.tempFilePaths;
- console.log(tempFilePaths);
- uni.showLoading({
- title: "图片上传中"
- });
- uni.uploadFile({
- url: that.apiWebUrl + '/data/doc/add',
- filePath: tempFilePaths[0],
- name: 'file',
- formData: {
- module: this.module
- },
- success: (res) => {
- let info = JSON.parse(res.data);
- uni.hideLoading();
- console.log(info);
- that.attaments.push(info.data);
- that.$emit("getUpFlie",that.attaments);
- },
- fail: () => {
- uni.hideLoading();
- uni.showToast("图片上传失败!");
- },
- });
-
- },
- //上传成功
- picSuccess(){
- uni.showToast({
- icon:'none',
- title: '上传成功',
- duration: 2000
- });
- },
- //上传失败
- picFail(){
- uni.showToast({
- icon:'none',
- title: '上传失败,请重新上传!',
- duration: 2000
- });
- },
- //删除图片
- picDelete(e){
- console.log(e);
- },
-
- },
- }
- </script>
- <style lang="scss" scoped>
- .upBox{
- width: 100%;
- display: block;
- }
- </style>
|