From c18cace60a848de0638466cd8f9a6ebe039665ff Mon Sep 17 00:00:00 2001
From: Lou <luzhiping@qqyjz.com>
Date: Thu, 21 Mar 2024 09:49:43 +0800
Subject: [PATCH] Merge branch 'master' of http://s16s652780.51mypc.cn:49896/r/jczz_app
---
mixin/uploadMixinPicCheck.js | 157 ++++++++++++++++++++++++++++++++++++++++++++++++++++
pages/circle/publish.vue | 2
2 files changed, 158 insertions(+), 1 deletions(-)
diff --git a/mixin/uploadMixinPicCheck.js b/mixin/uploadMixinPicCheck.js
new file mode 100644
index 0000000..8953cd2
--- /dev/null
+++ b/mixin/uploadMixinPicCheck.js
@@ -0,0 +1,157 @@
+import {
+ devUrl,
+ prodUrl,
+ clientId,
+ clientSecret
+} from '@/common/setting'
+
+import {
+ Base64
+} from '@/utils/base64.js';
+export default {
+ data() {
+ return {
+ form: {
+ images: []
+ },
+
+ uploadConfig: {
+ acceptImg: "image",
+ acceptVideo: 'video',
+ capture: ['album', 'camera'],
+ multiple: true,
+ maxCount: "5",
+ previewFullImage: true,
+ uploadText: "上传中",
+ url: prodUrl + "/blade-resource/oss/endpoint/put-file-attach-by-prefix-path"
+ },
+ }
+ },
+
+ created() {
+ this.getHeader()
+ },
+
+ methods: {
+ //获取头部
+ getHeader() {
+ let accessToken = uni.getStorageSync('accessToken');
+ let myHeader = {}
+ if (accessToken) {
+ myHeader['Blade-Auth'] = 'bearer ' + accessToken;
+ }
+ // 客户端认证参数
+ myHeader['Authorization'] = 'Basic ' + Base64.encode(clientId + ':' + clientSecret);
+ this.uploadConfig.header = myHeader
+ },
+
+ //上传方法
+ uploadFilePromise(url) {
+ return new Promise((resolve, reject) => {
+ let a = uni.uploadFile({
+ url: this.uploadConfig.url, //接口地址
+ filePath: url,
+ name: 'file',
+ header: this.uploadConfig.header,
+ formData: {
+ prefixPath: "",
+ isCheck: 1
+ },
+ success: (res) => {
+ let data = JSON.parse(res.data)
+ if (data.code == 200) {
+ //校验没有违法违规进行自己业务代码处理
+ setTimeout(() => {
+ resolve(data)
+ }, 1000)
+ } else {
+ // if (checkResult.errcode == '87014') {
+ wx.hideLoading();
+ wx.showModal({
+ content: '存在敏感内容,请更换图片',
+ showCancel: false,
+ confirmText: '明白了'
+ })
+ // } else {
+ // wx.hideLoading();
+ // wx.showModal({
+ // content: '其他错误,稍后再试',
+ // showCancel: false,
+ // confirmText: '明白了'
+ // })
+ // }
+ }
+ }
+ });
+ })
+ },
+
+ //上传成功后对返回数据进行处理
+ async afterReadImg(event, key = "images") {
+ // console.log(key)
+ // console.log(this.form[key]);
+ this.showLoading()
+ var that = this;
+ // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
+ let lists = [].concat(event.file)
+ console.log("form====>", this.form);
+ let fileListLen = this.form[key].length
+ lists.map((item) => {
+ this.form[key].push({
+ ...item,
+ status: 'uploading',
+ message: '上传中'
+ })
+ })
+ for (let i = 0; i < lists.length; i++) {
+ const result = await this.uploadFilePromise(lists[i].url)
+ that.form[key].splice(fileListLen, 1, Object.assign({}, {
+ url: result.data.link,
+ name: result.data.name
+ }))
+ fileListLen++
+ }
+
+ // let fileListLen = this.form.images.length
+ // lists.map((item) => {
+ // this.form.images.push({
+ // ...item,
+ // status: 'uploading',
+ // message: '上传中'
+ // })
+ // })
+ // for (let i = 0; i < lists.length; i++) {
+ // const result = await this.uploadFilePromise(lists[i].url)
+ // that.form.images.splice(fileListLen, 1, Object.assign({}, {
+ // url: result.data.link,
+ // name:result.data.name
+ // }))
+ // fileListLen++
+ // }
+
+
+ this.loadingClose()
+ },
+
+
+ //删除图片
+ deletePic(event, key = "images") {
+ this.form[key].splice(event.index, 1)
+ },
+
+ deletePics(event, key) {
+ console.log(event, key);
+ this[key].splice(event.index, 1)
+ },
+
+ showLoading() {
+ uni.showLoading({
+ mask: true,
+ title: '上传中'
+ })
+ },
+ loadingClose() {
+ uni.hideLoading()
+ },
+ }
+}
\ No newline at end of file
diff --git a/pages/circle/publish.vue b/pages/circle/publish.vue
index b5930b7..5c41f62 100644
--- a/pages/circle/publish.vue
+++ b/pages/circle/publish.vue
@@ -21,7 +21,7 @@
</template>
<script>
- import uploadMixin from "@/mixin/uploadMixin";
+ import uploadMixin from "@/mixin/uploadMixinPicCheck";
import { handlePublish } from "@/api/circle/circle.js"
export default {
mixins: [uploadMixin],
--
Gitblit v1.9.3