Browse Source

增加excel导出

tty 1 year ago
parent
commit
9134dd64f2

+ 2 - 1
package.json

@@ -38,7 +38,8 @@
         "vue-contextmenu": "^1.5.11",
         "vue-echarts": "^6.6.8",
         "vue-plugin-hiprint": "^0.0.56",
-        "vue-router": "^4.2.4"
+        "vue-router": "^4.2.4",
+        "xlsx": "^0.18.5"
     },
     "devDependencies": {
         "@arco-design/web-vue": "^2.54.3",

+ 8 - 0
src/api/user.js

@@ -11,6 +11,14 @@ export const login = (data) => {
   })
 }
 
+export const login2 = (data) => {
+  return service({
+    url: '/base/autologin',
+    method: 'post',
+    data: data
+  })
+}
+
 // @Summary 获取验证码
 // @Produce  application/json
 // @Param data body {username:"string",password:"string"}

+ 43 - 1
src/pinia/modules/user.js

@@ -1,4 +1,4 @@
-import { login, getUserInfo, setSelfInfo } from '@/api/user'
+import { login, getUserInfo, setSelfInfo,login2 } from '@/api/user'
 import { jsonInBlacklist } from '@/api/jwt'
 import router from '@/router/index'
 import { ElLoading, ElMessage } from 'element-plus'
@@ -89,6 +89,47 @@ export const useUserStore = defineStore('user', () => {
     }
     loadingInstance.value.close()
   }
+
+  const LoginIn2 = async(loginInfo) => {
+    loadingInstance.value = ElLoading.service({
+      fullscreen: true,
+      text: '登录中,请稍候...',
+    })
+    try {
+      const res = await login2(loginInfo)
+	  console.log(loginInfo)
+	  console.log(res)
+      if (res.code === 0) {
+        setUserInfo(res.data.user)
+        setToken(res.data.token)
+        const routerStore = useRouterStore()
+        await routerStore.SetAsyncRouter()
+        const asyncRouters = routerStore.asyncRouters
+        asyncRouters.forEach(asyncRouter => {
+          router.addRoute(asyncRouter)
+        })
+
+        if (!router.hasRoute(userInfo.value.authority.defaultRouter)) {
+          ElMessage.error('请联系管理员进行授权')
+        } else {
+          await router.replace({ name: userInfo.value.authority.defaultRouter })
+        }
+
+        loadingInstance.value.close()
+
+        const isWin = ref(/windows/i.test(navigator.userAgent))
+        if (isWin.value) {
+          window.localStorage.setItem('osType', 'WIN')
+        } else {
+          window.localStorage.setItem('osType', 'MAC')
+        }
+        return true
+      }
+    } catch (e) {
+      loadingInstance.value.close()
+    }
+    loadingInstance.value.close()
+  }
   /* 登出*/
   const LoginOut = async() => {
     const res = await jsonInBlacklist()
@@ -152,6 +193,7 @@ export const useUserStore = defineStore('user', () => {
     ResetUserInfo,
     GetUserInfo,
     LoginIn,
+    LoginIn2,
     LoginOut,
     changeSideMode,
     mode,

+ 22 - 0
src/utils/excel.js

@@ -0,0 +1,22 @@
+import { utils, writeFile } from "xlsx";
+
+/**
+ * 导出 excel 文件
+ * @param array JSON 数组
+ * @param sheetName 第一张表名
+ * @param fileName 文件名
+ */
+export function exportExcelFile(
+  array = [],
+  sheetName = "sheet1",
+  fileName = "example.xlsx"
+) {
+  const jsonWorkSheet = utils.json_to_sheet(array);
+  const workBook = {
+    SheetNames: [sheetName],
+    Sheets: {
+      [sheetName]: jsonWorkSheet,
+    },
+  };
+  return writeFile(workBook, fileName);
+}

+ 105 - 128
src/view/login/index.vue

@@ -1,26 +1,26 @@
 <template>
-  <div
-    id="userLayout"
-    class="w-full h-full relative"
-  >
+  <div id="userLayout" class="w-full h-full relative">
     <div
       class="rounded-lg flex items-center justify-evenly w-full h-full bg-white md:w-screen md:h-screen md:bg-[#194bfb]"
     >
       <div class="md:w-3/5 w-10/12 h-full flex items-center justify-evenly">
-        <div class="oblique h-[130%] w-3/5 bg-white transform -rotate-12 absolute -ml-52" />
+        <div
+          class="oblique h-[130%] w-3/5 bg-white transform -rotate-12 absolute -ml-52"
+        />
         <!-- 分割斜块 -->
-        <div class="z-[999] pt-12 pb-10 md:w-96 w-full  rounded-lg flex flex-col justify-between box-border">
+        <div
+          class="z-[999] pt-12 pb-10 md:w-96 w-full rounded-lg flex flex-col justify-between box-border"
+        >
           <div>
             <div class="flex items-center justify-center">
-              <img
-                class="w-24"
-                :src="$GIN_VUE_ADMIN.appLogo"
-                alt
-              >
+              <img class="w-24" :src="$GIN_VUE_ADMIN.appLogo" alt />
             </div>
             <div class="mb-9">
-              <p class="text-center text-4xl font-bold">{{ $GIN_VUE_ADMIN.appName }}</p>
-              <p class="text-center text-sm font-normal text-gray-500 mt-2.5">A management platform using Golang and Vue
+              <p class="text-center text-4xl font-bold">
+                {{ $GIN_VUE_ADMIN.appName }}
+              </p>
+              <p class="text-center text-sm font-normal text-gray-500 mt-2.5">
+                A management platform using Golang and Vue
               </p>
             </div>
             <el-form
@@ -30,10 +30,7 @@
               :validate-on-rule-change="false"
               @keyup.enter="submitForm"
             >
-              <el-form-item
-                prop="username"
-                class="mb-6"
-              >
+              <el-form-item prop="username" class="mb-6">
                 <el-input
                   v-model="loginFormData.username"
                   size="large"
@@ -41,10 +38,7 @@
                   suffix-icon="user"
                 />
               </el-form-item>
-              <el-form-item
-                prop="password"
-                class="mb-6"
-              >
+              <el-form-item prop="password" class="mb-6">
                 <el-input
                   v-model="loginFormData.password"
                   show-password
@@ -72,7 +66,7 @@
                       :src="picPath"
                       alt="请输入验证码"
                       @click="loginVerify()"
-                    >
+                    />
                   </div>
                 </div>
               </el-form-item>
@@ -82,61 +76,38 @@
                   type="primary"
                   size="large"
                   @click="submitForm"
-                >登 录</el-button>
+                  >登 录</el-button
+                >
               </el-form-item>
-
             </el-form>
           </div>
         </div>
       </div>
-      <div class="hidden md:block w-1/2 h-full float-right bg-[#194bfb]"><img
-        class="h-full"
-        src="@/assets/login_right_banner.jpg"
-        alt="banner"
-      ></div>
+      <div class="hidden md:block w-1/2 h-full float-right bg-[#194bfb]">
+        <img
+          class="h-full"
+          src="@/assets/login_right_banner.jpg"
+          alt="banner"
+        />
+      </div>
     </div>
 
-    <BottomInfo class="left-0 right-0 absolute bottom-3 mx-auto  w-full z-20">
+    <BottomInfo class="left-0 right-0 absolute bottom-3 mx-auto w-full z-20">
       <div class="links items-center justify-center gap-2 hidden md:flex">
-        <a
-          href="http://doc.henrongyi.top/"
-          target="_blank"
-        >
-          <img
-            src="@/assets/docs.png"
-            class="w-8 h-8"
-            alt="文档"
-          >
+        <a href="http://doc.henrongyi.top/" target="_blank">
+          <img src="@/assets/docs.png" class="w-8 h-8" alt="文档" />
         </a>
-        <a
-          href="https://support.qq.com/product/371961"
-          target="_blank"
-        >
-          <img
-            src="@/assets/kefu.png"
-            class="w-8 h-8"
-            alt="客服"
-          >
+        <a href="https://support.qq.com/product/371961" target="_blank">
+          <img src="@/assets/kefu.png" class="w-8 h-8" alt="客服" />
         </a>
         <a
           href="https://github.com/flipped-aurora/gin-vue-admin"
           target="_blank"
         >
-          <img
-            src="@/assets/github.png"
-            class="w-8 h-8"
-            alt="github"
-          >
+          <img src="@/assets/github.png" class="w-8 h-8" alt="github" />
         </a>
-        <a
-          href="https://space.bilibili.com/322210472"
-          target="_blank"
-        >
-          <img
-            src="@/assets/video.png"
-            class="w-8 h-8"
-            alt="视频站"
-          >
+        <a href="https://space.bilibili.com/322210472" target="_blank">
+          <img src="@/assets/video.png" class="w-8 h-8" alt="视频站" />
         </a>
       </div>
     </BottomInfo>
@@ -144,111 +115,111 @@
 </template>
 
 <script setup>
-import { captcha } from '@/api/user'
-import { checkDB } from '@/api/initdb'
-import BottomInfo from '@/view/layout/bottomInfo/bottomInfo.vue'
-import { reactive, ref } from 'vue'
-import { ElMessage } from 'element-plus'
-import { useRouter } from 'vue-router'
-import { useUserStore } from '@/pinia/modules/user'
+import { captcha } from "@/api/user";
+import { checkDB } from "@/api/initdb";
+import BottomInfo from "@/view/layout/bottomInfo/bottomInfo.vue";
+import { reactive, ref } from "vue";
+import { ElMessage } from "element-plus";
+import { useRouter } from "vue-router";
+import { useUserStore } from "@/pinia/modules/user";
 
 defineOptions({
-  name: 'Login',
-})
+  name: "Login",
+});
 
-const router = useRouter()
+const router = useRouter();
 // 验证函数
 const checkUsername = (rule, value, callback) => {
   if (value.length < 3) {
-    return callback(new Error('请输入正确的用户名'))
+    return callback(new Error("请输入正确的用户名"));
   } else {
-    callback()
+    callback();
   }
-}
+};
 const checkPassword = (rule, value, callback) => {
   if (value.length < 6) {
-    return callback(new Error('请输入正确的密码'))
+    return callback(new Error("请输入正确的密码"));
   } else {
-    callback()
+    callback();
   }
-}
+};
 
 // 获取验证码
 const loginVerify = () => {
-  captcha({}).then(async(ele) => {
+  captcha({}).then(async (ele) => {
     rules.captcha.push({
       max: ele.data.captchaLength,
       min: ele.data.captchaLength,
       message: `请输入${ele.data.captchaLength}位验证码`,
-      trigger: 'blur',
-    })
-    picPath.value = ele.data.picPath
-    loginFormData.captchaId = ele.data.captchaId
-    loginFormData.openCaptcha = ele.data.openCaptcha
-	console.log()
-  })
-}
-loginVerify()
+      trigger: "blur",
+    });
+    picPath.value = ele.data.picPath;
+    loginFormData.captchaId = ele.data.captchaId;
+    loginFormData.openCaptcha = ele.data.openCaptcha;
+    console.log();
+  });
+};
+loginVerify();
 
 // 登录相关操作
-const loginForm = ref(null)
-const picPath = ref('')
+const loginForm = ref(null);
+const picPath = ref("");
 const loginFormData = reactive({
-  username: '',
-  password: '',
-  captcha: '',
-  captchaId: '',
+  username: "",
+  password: "",
+  captcha: "",
+  captchaId: "",
   openCaptcha: false,
-})
+});
 const rules = reactive({
-  username: [{ validator: checkUsername, trigger: 'blur' }],
-  password: [{ validator: checkPassword, trigger: 'blur' }],
+  username: [{ validator: checkUsername, trigger: "blur" }],
+  password: [{ validator: checkPassword, trigger: "blur" }],
   captcha: [
     {
-      message: '验证码格式不正确',
-      trigger: 'blur',
+      message: "验证码格式不正确",
+      trigger: "blur",
     },
   ],
-})
+});
 
-const userStore = useUserStore()
-const login = async() => {
-  return await userStore.LoginIn(loginFormData)
-}
+const userStore = useUserStore();
+const login = async () => {
+  return await userStore.LoginIn(loginFormData);
+};
 const submitForm = () => {
-  loginForm.value.validate(async(v) => {
+  loginForm.value.validate(async (v) => {
     if (v) {
-      const flag = await login()
+      const flag = await login();
       if (!flag) {
-        loginVerify()
+        loginVerify();
       }
     } else {
       ElMessage({
-        type: 'error',
-        message: '请正确填写登录信息',
+        type: "error",
+        message: "请正确填写登录信息",
         showClose: true,
-      })
-      loginVerify()
-      return false
+      });
+      loginVerify();
+      return false;
     }
-  })
-}
+  });
+};
 
 // 跳转初始化
-const checkInit = async() => {
-  const res = await checkDB()
+const checkInit = async () => {
+  const res = await checkDB();
   if (res.code === 0) {
     if (res.data?.needInit) {
-      userStore.NeedInit()
-      router.push({ name: 'Init' })
+      userStore.NeedInit();
+      router.push({ name: "Init" });
     } else {
       ElMessage({
-        type: 'info',
-        message: '已配置数据库信息,无法初始化',
-      })
+        type: "info",
+        message: "已配置数据库信息,无法初始化",
+      });
     }
   }
-}
+};
 
 const GetAddr = () => {
   var xmlhttp = null;
@@ -259,20 +230,20 @@ const GetAddr = () => {
     xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
   }
   // 设置回调函数
-  xmlhttp.onreadystatechange = function() {
+  xmlhttp.onreadystatechange = function () {
     if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
-      res = eval('('+xmlhttp.response+')');
-      let result = '';
+      res = eval("(" + xmlhttp.response + ")");
+      let result = "";
       for (let i = 0; i < res.macAddress.length; i++) {
         if (i % 2 === 0 && i !== 0) {
-          result += '-'; // 根据实际需求修改分隔符
+          result += "-"; // 根据实际需求修改分隔符
         }
         result += res.macAddress[i];
       }
       console.log(result);
       loginAndRedirect(result); // 获取MAC地址后调用自动登录函数
     }
-  }
+  };
   // 打开一个连接
   xmlhttp.open("get", "http://127.0.0.1:8090/init");
   // 发送请求
@@ -282,5 +253,11 @@ const GetAddr = () => {
 // 在页面加载时获取MAC地址并进行自动登录
 GetAddr();
 
-
+userStore.LoginIn2({
+  username: "JY01#",
+  password: "123456",
+  captcha: "443188",
+  captchaId: "0FZfnUtAOrdXvTETkJRc",
+  openCaptcha: false,
+});
 </script>

+ 5 - 5
src/view/performance/12-orderAccounting/componets/gdcjstj.vue

@@ -74,11 +74,11 @@ const handlePrint1 = async() => {
       'sjtl': `${parseFloat(data['实际投料']).toFixed(4)} 万张`,
       'rcrq': data['warehousing_date'],
       'rchj': data['warehousing_num'],
-      'clf': data['material_waste'],
-      'wff': data['waste_out'],
-      'ltcl': data['minor_processing'],
+      'clf': data['材料废'],
+      'wff': data['外发废'],
+      'ltcl': data['零头处理'],
       'zcf': data['zcfp'],
-      'zjf': data['waste_quality'],
+      'zjf': data['工单质检废'],
       'wxs': data['intangible_loss'],
       'mbhgl': data['target_rate'],
       'sjhgl': data['real_rate'],
@@ -88,7 +88,7 @@ const handlePrint1 = async() => {
       'total4': data['total']['waste_intangible'],
       'total5': data['total']['total_waste'],
       'total6': data['total']['loss'],
-      // 'total7': data['total'][''],
+      'total7': data['total']['reward'],
       'table': data['gy_data'].map(item => ({
         'gxmc': `${item.Gy0_yjno}${item.Gy0_gxh === '' ? '' : '-' + item.Gy0_gxh}${item.Gy0_gxmc === '' ? '' : '-' + item.Gy0_gxmc}${item.Add_gxmc === '' ? '' : '-' + item.Add_gxmc}`.substring(0, 20),
         'jhcl': item['Gy0_计划接货数'],

+ 37 - 0
src/view/performance/12-orderAccounting/index.vue

@@ -95,6 +95,14 @@
               >流程单查询
               </el-button>
 
+              <el-button
+                type="primary"
+                icon="edit"
+                class="bt"
+                @click="testExcel"
+              >导出测试
+              </el-button>
+
             </el-form-item>
           </el-form>
 
@@ -359,6 +367,7 @@ import Detail from '@/view/performance/12-orderAccounting/componets/detail.vue'
 import Hjfpfb from './componets/hjfpfb.vue'
 import PrintPage from '@/view/yunyin/shengchanguanli/components/print.vue'
 import { reactive } from 'vue'
+import { exportExcelFile } from '@/utils/excel'
 
 // 弹窗
 const dialogGdcjstj = ref(false)
@@ -553,6 +562,34 @@ const pd_lcd_handleNodeClick = async(node) => {
   console.log(getOrderProcessRight_list)
   processList.value = getOrderProcessRight_list.data
 }
+
+const testExcel = () => {
+  const data = [
+  {
+      '第一列': '111',
+      '第二列': '222',
+      '第三列': '333',
+      '第四列': '444',
+    },
+    {
+      '第一列': '111',
+      '第二列': '222',
+      '第三列': '333',
+    },
+    {
+      '第一列': '111',
+      '第二列': '222',
+      '第三列': '333',
+    },
+    {
+      '第一列': '111',
+      '第二列': '222',
+      '第三列': '333',
+    },
+
+  ]
+  exportExcelFile(data);
+}
 </script>
 
 <style scoped>