Selaa lähdekoodia

fix: 绘制圆圈bug

zhangjie 1 vuosi sitten
vanhempi
commit
a2969f4407

+ 9 - 2
electron/preload/api.ts

@@ -73,14 +73,21 @@ function drawTrack(
       // circle
       if (track.type === 'circle') {
         const { x0, y0, x1, y1 } = track.option as DrawTrackCircleOption;
-        gmObj.drawCircle(x0, y0, x1, y1).stroke(defaultColor, 2);
+        const rx = (x1 - x0) / 2;
+        const ry = (y1 - y0) / 2;
+        const cx = x0 + rx;
+        const cy = y0 + ry;
+        gmObj
+          .stroke(defaultColor, 2)
+          .fill('none')
+          .drawEllipse(cx, cy, cx, cy, 0, 360);
         return;
       }
 
       // line
       if (track.type === 'line') {
         const { x0, y0, x1, y1 } = track.option as DrawTrackLineOption;
-        gmObj.drawLine(x0, y0, x1, y1).stroke(defaultColor, 2);
+        gmObj.stroke(defaultColor, 2).fill('none').drawLine(x0, y0, x1, y1);
       }
     });
 

+ 15 - 0
src/api/types/user.ts

@@ -11,3 +11,18 @@ export interface SchoolItem {
   code: string;
   logo: string;
 }
+
+export interface MenuItem {
+  id: string;
+  name: string;
+  url: string;
+  type: string;
+  parentId: string;
+  sequence: number;
+  enable: boolean;
+}
+
+export interface SysMenuRes {
+  userId: string;
+  privileges: MenuItem[];
+}

+ 4 - 1
src/api/user.ts

@@ -1,6 +1,6 @@
 import axios from 'axios';
 import { UserState } from '@/store/modules/user/types';
-import type { LoginData, SchoolItem } from './types/user';
+import type { LoginData, SchoolItem, SysMenuRes } from './types/user';
 
 export function login(data: LoginData): Promise<UserState> {
   return axios.post('/api/admin/common/login', data);
@@ -10,6 +10,9 @@ export function schoolList(): Promise<SchoolItem[]> {
   return axios.post('/api/admin/client/school/list', {});
 }
 
+export function sysMenu(): Promise<SysMenuRes> {
+  return axios.post('/api/admin/common/get_menu', {});
+}
 export function userLogout() {
   return axios.post('/api/admin/common/logout', {});
 }

+ 15 - 1
src/views/login/login/index.vue

@@ -62,13 +62,14 @@
   import { useRouter } from 'vue-router';
   import type { FormInstance } from '@arco-design/web-vue/es/form';
   import useLoading from '@/hooks/loading';
-  import { login, schoolList } from '@/api/user';
+  import { login, schoolList, sysMenu } from '@/api/user';
   import { getBase64 } from '@/utils/crypto';
   import { useAppStore, useUserStore } from '@/store';
   import { UserSchoolInfoType } from '@/store/modules/user/types';
   import type { LoginData } from '@/api/types/user';
   import { FormRules, OptionListItem } from '@/types/global';
   import { objAssign } from '@/utils/utils';
+  import { Message } from '@arco-design/web-vue';
 
   defineOptions({
     name: 'Login',
@@ -142,6 +143,19 @@
       );
       data.curSchoolInfo = curSchool || ({} as UserSchoolInfoType);
     }
+
+    userStore.setInfo(data);
+
+    const menuRes = await sysMenu();
+    const validMenu = menuRes.privileges.find(
+      (item) => item.url === 'ScoreManage'
+    );
+    if (!validMenu) {
+      userStore.resetInfo();
+      Message.error('您没有权限!');
+      return;
+    }
+    data.privilegeId = validMenu.id;
     userStore.setInfo(data);
 
     router.push({

+ 15 - 0
src/views/login/test-page/index.vue

@@ -3,6 +3,8 @@
     <h1>TestPage1</h1>
     <a-button type="primary" @click="toOpenFile">打开文件</a-button>
     <a-button type="primary" @click="toDownloadFile">下载文件</a-button>
+    <a-button type="primary" @click="toDrawCircle('circle')">绘制圆圈</a-button>
+    <a-button type="primary" @click="toDrawCircle('line')">绘制长线</a-button>
     <br />
     <img v-if="originImg" :src="originImg" alt="原图" />
     <br />
@@ -48,4 +50,17 @@
     const res = await window.api.downloadImage(url, outpath);
     console.log(res);
   }
+
+  async function toDrawCircle(type: 'circle' | 'line') {
+    const url =
+      'https://oss-file.qmth.com.cn/teachcloud-dps-dev-private/sheet/506931097515331584/511142910851289088/2024000001/1-1.jpg?Expires=1717638293&OSSAccessKeyId=key&Signature=UYsoE6XTZ3KR8cng7liDN1zmwj0%3D';
+    const outpath =
+      '/Users/chulin/develop/workspace/tcs/teachcloud-mark-tool/store/temp/122.jpg';
+    await window.api.drawTrack(
+      url,
+      [{ type, option: { x0: 200, y0: 200, x1: 200, y1: 110 } }],
+      outpath
+    );
+    cropImg.value = `local://${outpath}`;
+  }
 </script>