Forráskód Böngészése

Merge branch 'feature_20250310_使用原生手机拍照,优化企业微信拍照模糊问题' into uat(dev)

# Conflicts:
#	src/views/home/index.vue
zhujindu 8 hónapja
szülő
commit
499a7d4e50

+ 10 - 0
src/api/H5Camera.js

@@ -0,0 +1,10 @@
+import request from '@/utils/request';
+
+// 获取阿里云oss STS token
+export function getSTSToken(query) {
+  return request({
+    url: '/mobile/getSTSToken',
+    method: 'get',
+    params: query,
+  });
+}

+ 9 - 0
src/api/week.js

@@ -8,3 +8,12 @@ export function selectAllocationPermission(query) {
     params: query,
   });
 }
+
+// 设置用户的拍照方式
+export function setPhotoMethod(query) {
+  return request({
+    url: '/mobile/setPhotoMethod',
+    method: 'get',
+    params: query,
+  });
+}

+ 6 - 0
src/router/index.js

@@ -647,6 +647,12 @@ const router = new VueRouter({
             title: '客资跟进',
           },
         },
+        {
+          path: '/systemSettings',
+          name: 'systemSettings',
+          component: () => import('@/views/week/systemSettings.vue'),
+          meta: { title: '设置' },
+        },
       ],
     },
     {

+ 14 - 11
src/utils/uploadAliOss.js

@@ -1,5 +1,5 @@
 const OSS = require('ali-oss');
-import { restartProcess } from '@/api/index';
+import { getSTSToken } from '@/api/H5Camera';
 
 // 自定义请求头
 const headers = {
@@ -14,7 +14,6 @@ const headers = {
   // 指定PutObject操作时是否覆盖同名目标Object。此处设置为true,表示禁止覆盖同名Object。
   'x-oss-forbid-overwrite': 'true',
 };
-
 export function dataURLtoFile(dataurl, filename) {
   let arr = dataurl.split(','),
     mime = arr[0].match(/:(.*?);/)[1],
@@ -38,27 +37,31 @@ let credentials = null;
 async function uploadAliOss(base64, filename) {
   if (isCredentialsExpired(credentials)) {
     // 获取 STS token.
-    const response = await restartProcess();
-    if (!response.ok) {
+    const response = await getSTSToken();
+    if (response.code != 200 || !response.data) {
       // 处理错误的HTTP状态码。
-      throw new Error(`获取STS令牌失败: ${response.status} ${response.statusText}`);
+      let err = `获取STS令牌失败: ${response.msg}`;
+      throw new Error(err);
     }
-    credentials = await response.json();
+    credentials = await response.data;
   }
   const client = new OSS({
-    region: 'cdn-svs-test.nipponpaint.com.cn',
+    region: 'cn-shanghai',
     // yourBucketName填写Bucket名称。
     bucket: 'svs-test',
-    accessKeyId: credentials.AccessKeyId,
-    accessKeySecret: credentials.AccessKeySecret,
-    stsToken: credentials.SecurityToken,
+    accessKeyId: credentials.accessKeyId,
+    accessKeySecret: credentials.accessKeySecret,
+    stsToken: credentials.securityToken,
+    secure: true,
   });
   let file = dataURLtoFile(base64, filename);
   try {
     const result = await client.put(filename, file, { headers });
     console.log(result);
+    return result;
   } catch (e) {
     console.log(e);
+    throw new Error(e);
   }
 }
 /**
@@ -68,7 +71,7 @@ function isCredentialsExpired(credentials) {
   if (!credentials) {
     return true;
   }
-  const expireDate = new Date(credentials.Expiration);
+  const expireDate = new Date(credentials.expiration);
   const now = new Date();
   // 如果有效期不足一分钟,视为过期。
   return expireDate.getTime() - now.getTime() <= 60000;

+ 20 - 2
src/views/home/index.vue

@@ -1,7 +1,12 @@
 <template>
   <div class="homePage" ref="homePage">
     <div class="content">
-      <van-nav-bar class="navBar" left-arrow title="门店拜访" @click-left="onClickLeft" />
+      <van-nav-bar class="navBar" left-arrow title="门店拜访" @click-left="onClickLeft">
+        <template #right>
+          <!-- 原生自带拍照 -->
+          <H5Camera @getImg="getImg" />
+        </template>
+      </van-nav-bar>
       <van-tabs
         class="myTab"
         type="card"
@@ -46,9 +51,11 @@ import ABtarget from './ABtarget.vue';
 import { mapState } from 'vuex';
 import bottomBtn from './bottomBtn.vue';
 import { getTicketFun } from '@/utils/TXApiFun';
+import uploadAliOss from '@/utils/uploadAliOss';
+import H5Camera from '@/components/H5Camera';
 export default {
   name: 'home',
-  components: { tabBar, hintTabPage, ABtarget, bottomBtn },
+  components: { tabBar, hintTabPage, ABtarget, bottomBtn, H5Camera },
   computed: {
     ...mapState({
       userInfo: (state) => state.user.userInfo,
@@ -122,6 +129,17 @@ export default {
     });
   },
   methods: {
+    // 原生H5拍照图片
+    // url: base64
+    getImg(base64) {
+      uploadAliOss(base64, '测试111')
+        .then((res) => {
+          console.log('res:' + res);
+        })
+        .catch((err) => {
+          console.log('err:' + err);
+        });
+    },
     onRefresh() {
       this.getDict(true);
       this.isLoading = false;

+ 7 - 0
src/views/week/index.vue

@@ -44,6 +44,13 @@
             </template>
           </van-cell>
         </van-cell-group>
+        <van-cell-group inset class="mtb10">
+          <van-cell title="设置" is-link to="/systemSettings">
+            <template #icon>
+              <van-icon name="setting-o" class="zicon" color="#0158ba" />
+            </template>
+          </van-cell>
+        </van-cell-group>
         <!--      客资类-->
         <van-cell-group inset class="mtb10">
           <van-cell title="客资&投诉任务" to="/clew" v-if="customerClueButton">

+ 60 - 4
src/views/week/systemSettings.vue

@@ -1,19 +1,75 @@
 <template>
-  <div class="systemSettings">systemSettings</div>
+  <div class="systemSettings">
+    <van-nav-bar class="navBar" title="设置" left-arrow @click-left="onClickLeft" />
+    <div class="content">
+      <div class="module">
+        <div class="title">拜访设置</div>
+        <div class="box">
+          <div class="label">设置</div>
+          <div class="value">
+            <van-switch v-model="switchChecked" size="20" @change="change" />
+          </div>
+        </div>
+      </div>
+    </div>
+  </div>
 </template>
 <script>
+import { mapState } from 'vuex';
+import { setPhotoMethod } from '@/api/week';
 export default {
   name: 'systemSettings',
+  computed: {
+    ...mapState({
+      userInfo: (state) => state.user.userInfo,
+    }),
+  },
   data() {
-    return {};
+    return {
+      switchChecked: false,
+    };
+  },
+  created() {
+    this.switchChecked = this.userInfo.photoMethod == 0 ? false : true;
+  },
+  methods: {
+    change(value) {
+      console.log(value);
+      this.toastLoading(0, '加载中...', true);
+      setPhotoMethod({ photoMethod: value ? 1 : 0 }).then((res) => {
+        this.toastLoading().clear();
+        if (res.code == 200) {
+          this.$toast('设置成功');
+        }
+      });
+    },
+    onClickLeft() {
+      this.$router.go(-1);
+    },
   },
-  methods: {},
 };
 </script>
 <style lang="scss" scoped>
 .systemSettings {
   width: 100%;
   height: 100%;
-  background: #fff;
+  .content {
+    margin: 10px 16px;
+    .module {
+      margin-bottom: 10px;
+      .title {
+        font-size: 16px;
+        padding: 10px 0;
+      }
+      .box {
+        background: #fff;
+        display: flex;
+        align-items: center;
+        justify-content: space-between;
+        padding: 10px;
+        font-size: 16px;
+      }
+    }
+  }
 }
 </style>