{"remainingRequest":"/data/jenkins/workspace/mer.mall2.baibaodun.cn/node_modules/vue-loader/lib/index.js??vue-loader-options!/data/jenkins/workspace/mer.mall2.baibaodun.cn/src/components/base/uploadPicture.vue?vue&type=script&lang=js","dependencies":[{"path":"/data/jenkins/workspace/mer.mall2.baibaodun.cn/src/components/base/uploadPicture.vue","mtime":1720764823951},{"path":"/data/jenkins/workspace/mer.mall2.baibaodun.cn/node_modules/babel-loader/lib/index.js","mtime":456789000000},{"path":"/data/jenkins/workspace/mer.mall2.baibaodun.cn/node_modules/cache-loader/dist/cjs.js","mtime":499162500000},{"path":"/data/jenkins/workspace/mer.mall2.baibaodun.cn/node_modules/vue-loader/lib/index.js","mtime":499162500000}],"contextDependencies":[],"result":["//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n\n// +----------------------------------------------------------------------\n// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]\n// +----------------------------------------------------------------------\n// | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved.\n// +----------------------------------------------------------------------\n// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权\n// +----------------------------------------------------------------------\n// | Author: CRMEB Team \n// +----------------------------------------------------------------------\n\nimport {\n addCategroy,\n listCategroy,\n treeCategroy,\n infoCategroy,\n updateCategroy,\n deleteCategroy,\n} from '@/api/categoryApi';\nimport { fileImageApi, fileListApi, fileDeleteApi, attachmentMoveApi } from '@/api/systemSetting';\nimport { getToken } from '@/utils/auth';\nimport { checkPermi } from '@/utils/permission'; // 权限判断函数\nimport { VueCropper } from 'vue-cropper';\n\nexport default {\n name: 'uploadPicture',\n props: {\n pictureType: {\n type: String,\n default: '',\n },\n isMore: {\n type: String,\n default: '1',\n },\n modelName: {\n type: String,\n default: '',\n },\n checkedMore: {\n type: Array,\n default: () => [],\n },\n labelName: {\n type: String,\n default: '',\n },\n },\n components: {\n VueCropper,\n },\n data() {\n return {\n uploadName: '上传',\n fixed: false,\n fixedNumber: [16, 9],\n option: {\n img: '',\n size: 1,\n full: false,\n outputType: 'png',\n canMove: true,\n fixedBox: false,\n original: false,\n canMoveBox: true,\n autoCrop: false,\n // 只有自动截图开启 宽度高度才生效\n // autoCropWidth: 160,\n // autoCropHeight: 150,\n centerBox: false,\n high: true,\n max: 99999,\n },\n picId: '',\n newPicId: '',\n crap: false,\n previews: {},\n visiblePic: false,\n loadingPic: false,\n loading: false,\n modals: false,\n allTreeList: [],\n categoryProps: {\n value: 'id',\n label: 'name',\n children: 'child',\n expandTrigger: 'hover',\n checkStrictly: true,\n emitPath: false,\n },\n editPram: {\n pid: 0,\n name: '',\n type: 2,\n sort: 1,\n status: 0,\n url: 'url',\n id: 0,\n },\n visible: false,\n bizTitle: '',\n sleOptions: {\n attrId: '',\n pid: '',\n },\n list: [],\n grid: {\n xl: 7,\n lg: 7,\n md: 7,\n sm: 7,\n xs: 24,\n },\n grid2: {\n xl: 17,\n lg: 17,\n md: 17,\n sm: 17,\n xs: 24,\n },\n filterText: '',\n treeData: [],\n treeData2: [],\n defaultProps: {\n children: 'child',\n label: 'name',\n },\n tableData: {\n page: 1,\n limit: 20,\n pid: 0,\n attType: 'jpg,jpeg,gif,png,bmp,PNG,JPG',\n },\n classifyId: 0,\n myHeaders: { 'X-Token': getToken() },\n treeFrom: {\n status: -1,\n type: 2,\n },\n pictrueList: {\n list: [],\n total: 0,\n },\n isShowPic: false,\n checkPicList: [],\n ids: [],\n listPram: {\n pid: 0,\n type: 2,\n status: 0,\n name: '',\n page: 1,\n limit: 9999,\n },\n localImg: '',\n videoStatus: false,\n typeDate: 'pic',\n };\n },\n watch: {\n filterText(val) {\n this.$refs.tree.filter(val);\n },\n },\n mounted() {\n if (this.labelName) {\n this.option.fixedBox = true;\n this.option.autoCropWidth = 200;\n this.option.autoCropHeight = 100;\n let str = this.labelName;\n let regex = /\\((.+?)\\)/g; // 中括号\n let regexs = /((.+?))/g; // 中文小括号\n // if(str.match(regex)){\n // str = str.match(regex)[0].replace(\"(\", \"\").replace(\")\", \"\");\n // }else{\n // str = str.match(regexs)[0].replace(\"(\", \"\").replace(\")\", \"\");\n // }\n // console.log(typeof str);\n }\n this.pictureType ? (this.tableData.limit = 30) : (this.tableData.limit = 20);\n if (this.$route && this.$route.query.field === 'dialog') import('../js/internal.js');\n if (checkPermi(['merchant:category:list:tree'])) this.getList();\n if (checkPermi(['merchant:attachment:list'])) this.getFileList();\n },\n methods: {\n checkPermi,\n // 选取图片后自动回调,里面可以获取到文件\n imgSaveToUrl(event) {\n // 也可以用file\n this.localFile = event.raw; // 或者 this.localFile=file.raw\n\n // 转换操作可以不放到这个函数里面,\n // 因为这个函数会被多次触发,上传时触发,上传成功也触发\n let reader = new FileReader();\n reader.readAsDataURL(this.localFile); // 这里也可以直接写参数event.raw\n\n // 转换成功后的操作,reader.result即为转换后的DataURL ,\n // 它不需要自己定义,你可以console.integralLog(reader.result)看一下\n reader.onload = () => {\n // console.integralLog(reader.result)\n };\n\n /* 另外一种本地预览方法 */\n let URL = window.URL || window.webkitURL;\n this.localImg = URL.createObjectURL(event.raw);\n // 转换后的地址为 blob:http://xxx/7bf54338-74bb-47b9-9a7f-7a7093c716b5\n },\n closeModel() {\n this.$refs['editPram'].resetFields();\n },\n handlerSubmit(formName) {\n this.$refs[formName].validate((valid) => {\n if (valid) {\n if (this.editPram.pid > 0) {\n if (this.editPram.pid === this.editPram.id) return this.$message.warning('上级分类不能选当前分类');\n }\n this.bizTitle === '添加分类'\n ? addCategroy(this.editPram).then((data) => {\n this.$message.success('创建成功');\n this.visible = false;\n this.getList();\n })\n : updateCategroy(this.editPram).then((data) => {\n this.$message.success('编辑成功');\n this.visible = false;\n this.getList();\n });\n } else {\n return false;\n }\n });\n },\n // 表单分类\n handlerGetList() {\n let datas = {\n name: '全部图片',\n id: '',\n };\n treeCategroy(this.treeFrom).then((data) => {\n this.allTreeList = data;\n this.allTreeLis.unshift(datas);\n });\n },\n // 搜索分类\n filterNode(value, data) {\n if (!value) return true;\n return data.name.indexOf(value) !== -1;\n },\n // 所有分类\n getList() {\n const data = {\n name: '全部图片',\n id: 0,\n };\n treeCategroy(this.treeFrom).then((res) => {\n this.treeData = res;\n this.treeData.unshift(data);\n this.treeData2 = [...this.treeData];\n });\n },\n // 添加分类\n onAdd(id) {\n this.tableData.pid = id;\n this.bizTitle = '添加分类';\n this.visible = true;\n if (id)\n this.editPram = {\n pid: id,\n name: '',\n type: 2,\n sort: 1,\n status: 0,\n url: 'url',\n id: 0,\n };\n },\n // 编辑\n onEdit(id) {\n this.bizTitle = '编辑分类';\n this.loading = true;\n infoCategroy({ id: id }).then((res) => {\n this.editPram = res;\n this.loading = false;\n });\n this.visible = true;\n },\n // 删除\n handleDelete(id) {\n this.$modalSure().then(() => {\n deleteCategroy({ id: id }).then(() => {\n this.$message.success('删除成功');\n this.getList();\n });\n });\n },\n handleNodeClick(data) {\n this.checkPicList = [];\n this.pictrueList.list = [];\n this.tableData.pid = data.id;\n this.tableData.page = 1;\n this.getFileList();\n },\n // 上传\n handleUploadForm(param) {\n const formData = new FormData();\n const data = {\n model: this.modelName ? this.modelName : this.$route.path.split('/')[1],\n pid: this.tableData.pid ? this.tableData.pid : 0,\n };\n formData.append('multipart', param.file);\n this.uploadPic(formData, data);\n },\n uploadPic(formData, data) {\n let loading = this.$loading({\n lock: true,\n text: '上传中,请稍候...',\n spinner: 'el-icon-loading',\n background: 'rgba(0, 0, 0, 0.7)',\n });\n fileImageApi(formData, data)\n .then((res) => {\n loading.close();\n this.$message.success('上传成功');\n this.tableData.page = 1;\n this.getFileList();\n this.onCallback();\n })\n .catch((res) => {\n loading.close();\n });\n },\n // 文件列表\n getFileList() {\n if (this.tableData.pid === 0) this.tableData.pid = null;\n this.loadingPic = true;\n fileListApi(this.tableData)\n .then(async (res) => {\n this.pictrueList.list = res.list;\n if (this.tableData.page === 1 && this.pictrueList.list.length > 0)\n this.pictrueList.list[0].localImg = this.localImg;\n if (this.pictrueList.list.length) {\n this.isShowPic = false;\n } else {\n this.isShowPic = true;\n }\n this.pictrueList.total = res.total;\n this.checkPicList = [];\n this.loadingPic = false;\n })\n .catch(() => {\n this.loadingPic = false;\n });\n },\n pageChange(page) {\n this.tableData.page = page;\n this.checkPicList = [];\n this.getFileList();\n },\n handleSizeChange(val) {\n this.tableData.limit = val;\n this.getFileList();\n },\n // 选中图片\n changImage(item, index, row) {\n let activeIndex = 0;\n if (!item.isSelect) {\n this.$set(item, 'isSelect', true);\n this.checkPicList.push(item);\n } else {\n this.$set(item, 'isSelect', !item.isSelect);\n this.checkPicList.map((el, index) => {\n if (el.attId == item.attId) {\n activeIndex = index;\n }\n });\n this.checkPicList.splice(activeIndex, 1);\n }\n this.ids = [];\n this.checkPicList.map((item, i) => {\n this.ids.push(item.attId);\n });\n if (this.checkPicList.length > 0) {\n this.uploadName = '裁剪图片';\n } else {\n this.uploadName = '上传';\n }\n\n this.pictrueList.list.map((el, i) => {\n if (el.isSelect) {\n this.checkPicList.filter((el2, j) => {\n if (el.attId == el2.attId) {\n el.num = j + 1;\n this.$nextTick(() => {\n this.pictrueList.list;\n });\n }\n });\n } else {\n el.num = 0;\n }\n });\n },\n // 点击使用选中图片\n checkPics() {\n if (!this.checkPicList.length) return this.$message.warning('请先选择图片');\n if (this.$route && this.$route.query.field === 'dialog') {\n let str = '';\n for (let i = 0; i < this.checkPicList.length; i++) {\n str += '';\n }\n /* eslint-disable */\n nowEditor.dialog.close(true);\n nowEditor.editor.setContent(str, true);\n } else {\n if (this.isMore === '1' && this.checkPicList.length > 1) {\n return this.$message.warning('最多只能选一张图片');\n }\n\n this.$emit('getImage', [...this.checkedMore, ...this.checkPicList]);\n }\n },\n // 删除图片\n editPicList(tit) {\n if (!this.checkPicList.length) return this.$message.warning('请先选择图片');\n this.$modalSure().then(() => {\n fileDeleteApi(this.ids.join(',')).then(() => {\n this.$message.success('刪除成功');\n this.tableData.page = 1;\n this.getFileList();\n this.checkPicList = [];\n this.uploadName = '上传';\n });\n });\n },\n // 移动分类点击\n handleSelClick(node) {\n if (this.ids.length) {\n this.sleOptions = {\n attrId: this.ids.join(','),\n pid: node.id,\n };\n this.getMove();\n } else {\n this.$message.warning('请先选择图片');\n }\n },\n getMove() {\n attachmentMoveApi(this.sleOptions)\n .then(async (res) => {\n this.$message.success('操作成功');\n this.clearBoth();\n this.tableData.page = 1;\n this.getFileList();\n })\n .catch((res) => {\n this.clearBoth();\n });\n },\n clearBoth() {\n this.sleOptions = {\n attrId: '',\n pid: '',\n };\n this.checkPicList = [];\n this.ids = [];\n },\n videoChange(val) {\n if (val == false) {\n this.$set(this.tableData, 'attType', 'jpg,jpeg,gif,png,bmp,PNG,JPG');\n this.tableData.page = 1;\n this.getFileList();\n } else {\n this.$set(this.tableData, 'attType', 'video/mp4');\n this.tableData.page = 1;\n this.getFileList();\n }\n },\n radioChange(val) {\n if (val === 'video') {\n this.videoChange(true);\n } else {\n this.videoChange(false);\n }\n },\n /**\n * 裁剪图片\n * @returns {ElMessageComponent}\n */\n startCrop() {\n this.crap = true;\n this.$refs.cropper.startCrop();\n },\n stopCrop() {\n // stop\n this.crap = false;\n this.$refs.cropper.stopCrop();\n },\n clearCrop() {\n // clear\n this.$refs.cropper.clearCrop();\n },\n handleChangeImage() {\n if (this.checkPicList.length > 1) {\n return this.$message.warning('最多只能选一张图片');\n }\n this.visiblePic = true;\n if (this.checkPicList.length > 0) this.imageToBase64(this.checkPicList[0].sattDir);\n },\n saveNewPic() {\n // if (!this.newPicId) {\n // return this.$message.warning(\"请上传裁剪后的图片\");\n // }\n this.$refs.cropper.getCropBlob((data) => {\n this.downImg = window.URL.createObjectURL(data);\n // aLink.download = this.downImg;\n this.$emit('getImage', [\n {\n sattDir: this.downImg,\n },\n ]);\n });\n },\n onCallback() {\n this.visiblePic = false;\n this.option.img = '';\n this.stopCrop();\n this.clearCrop();\n },\n changeScale(num) {\n num = num || 1;\n this.$refs.cropper.changeScale(num);\n },\n rotateLeft() {\n this.$refs.cropper.rotateLeft();\n },\n rotateRight() {\n this.$refs.cropper.rotateRight();\n },\n // 实时预览函数\n realTime(data) {\n this.previews = data;\n },\n //image转Base64\n imageToBase64(file) {\n //一定要设置为let,不然图片不显示\n let image = new Image();\n //解决跨域问题\n image.setAttribute('crossOrigin', 'anonymous');\n let imageUrl = file;\n image.src = imageUrl;\n //image.onload为异步加载\n image.onload = () => {\n var canvas = document.createElement('canvas');\n canvas.width = image.width;\n canvas.height = image.height;\n var context = canvas.getContext('2d');\n context.drawImage(image, 0, 0, image.width, image.height);\n\n var quality = 0.8;\n //这里的dataurl就是base64类型\n var dataURL = canvas.toDataURL('image/jpeg', quality); //使用toDataUrl将图片转换成jpeg的格式,不要把图片压缩成png,因为压缩成png后base64的字符串可能比不转换前的长!\n this.option.img = dataURL;\n };\n },\n // 将base64转换为文件 百度随便找的 看需求使用\n dataURLtoFile(dataurl, filename) {\n var arr = dataurl.split(','),\n mime = arr[0].match(/:(.*?);/)[1],\n bstr = atob(arr[1]),\n n = bstr.length,\n u8arr = new Uint8Array(n);\n while (n--) {\n u8arr[n] = bstr.charCodeAt(n);\n }\n return new File([u8arr], filename, { type: mime });\n },\n uploadNewPic() {\n this.$refs.cropper.getCropData((data) => {\n let name = new Date().getTime();\n let file = this.dataURLtoFile(data, `${name}.png`);\n const datas = {\n model: this.modelName ? this.modelName : 'product',\n pid: this.tableData.pid ? this.tableData.pid : 0,\n };\n let formData = new FormData();\n formData.append('multipart', file);\n this.uploadPic(formData, datas);\n });\n },\n down(type) {\n // event.preventDefault()\n var aLink = document.createElement('a');\n aLink.download = 'author-img';\n // 输出\n if (type === 'blob') {\n this.$refs.cropper.getCropBlob((data) => {\n this.downImg = window.URL.createObjectURL(data);\n // aLink.download = this.downImg;\n aLink.href = window.URL.createObjectURL(data);\n aLink.click();\n });\n } else {\n this.$refs.cropper.getCropData((data) => {\n this.downImg = data;\n aLink.href = data;\n aLink.click();\n });\n }\n },\n uploadImg(e) {\n //上传图片\n var file = e.target.files[0];\n if (!/\\.(gif|jpg|jpeg|png|bmp|GIF|JPG|PNG)$/.test(e.target.value)) {\n this.$message.warning('图片类型必须是.gif,jpeg,jpg,png,bmp中的一种');\n return false;\n }\n var reader = new FileReader();\n reader.onload = (e) => {\n let data;\n if (typeof e.target.result === 'object') {\n // 把Array Buffer转化为blob 如果是base64不需要\n data = window.URL.createObjectURL(new Blob([e.target.result]));\n } else {\n data = e.target.result;\n }\n this.option.img = data;\n };\n // 转化为base64\n // reader.readAsDataURL(file)\n // 转化为blob\n reader.readAsArrayBuffer(file);\n },\n imgLoad(msg) {\n console.log(msg, 'msg');\n },\n },\n};\n",null]}