From 67461f55748c32d885db965bdff6c2cc63eb327b Mon Sep 17 00:00:00 2001
From: zhangwencui <1064582902@qq.com>
Date: 星期一, 09 二月 2026 13:36:24 +0800
Subject: [PATCH] 推送cid传值,以及打卡签到模块开发

---
 src/pages/login.vue |  488 +++++++++++++++++++++++++++++-------------------------
 1 files changed, 263 insertions(+), 225 deletions(-)

diff --git a/src/pages/login.vue b/src/pages/login.vue
index a2e0d33..9135392 100644
--- a/src/pages/login.vue
+++ b/src/pages/login.vue
@@ -1,264 +1,302 @@
 <template>
   <view class="normal-login-container">
     <view class="logo-content">
-<!--      <image style="width: 100rpx;height: 100rpx;" :src="globalConfig.appInfo.logo" mode="widthFix">-->
-<!--      </image>-->
       <text>璐﹀彿瀵嗙爜鐧诲綍</text>
     </view>
     <view class="login-form-content">
       <view class="input-item flex align-center">
-				<up-input prefixIcon="account" placeholder="璇疯緭鍏ヨ处鍙�" border="bottom"
-									@blur="getUserLoginFacotryList"
-									maxlength="30" v-model="loginForm.username" clearable></up-input>
+        <up-input prefixIcon="account"
+                  placeholder="璇疯緭鍏ヨ处鍙�"
+                  border="bottom"
+                  @blur="getUserLoginFacotryList"
+                  maxlength="30"
+                  v-model="loginForm.userName"
+                  clearable></up-input>
       </view>
       <view class="input-item flex align-center">
-				<up-input prefixIcon="lock" placeholder="璇疯緭鍏ュ瘑鐮�" border="bottom" maxlength="20" v-model="loginForm.password" clearable type="password"></up-input>
+        <up-input prefixIcon="lock"
+                  placeholder="璇疯緭鍏ュ瘑鐮�"
+                  border="bottom"
+                  maxlength="20"
+                  v-model="loginForm.password"
+                  clearable
+                  type="password"></up-input>
       </view>
-			<view class="input-item flex align-center select-container">
-				<up-icon name="tags" size="18"></up-icon>
-				<up-picker-data
-					v-model="loginForm.factoryId"
-					title="璇烽�夋嫨鍏徃"
-					:options="factoryList"
-					valueKey="id"
-					labelKey="name">
-				</up-picker-data>
-			</view>
       <view>
-        <button @click="handleLogin" class="login-btn cu-btn block bg-blue lg round">鐧诲綍</button>
+        <button @click="handleLogin"
+                class="login-btn cu-btn block bg-blue lg round">鐧诲綍</button>
       </view>
     </view>
-		<!-- 璁颁綇瀵嗙爜閫夐」 -->
-		<view class="remember-password">
-			<up-checkbox
-				:customStyle="{marginBottom: '8px'}"
-				label="璁颁綇瀵嗙爜"
-				name="agree"
-				usedAlone
-				v-model:checked="rememberPassword"
-			>
-			</up-checkbox>
-		</view>
+    <!-- 璁颁綇瀵嗙爜閫夐」 -->
+    <view class="remember-password">
+      <up-checkbox :customStyle="{marginBottom: '8px'}"
+                   label="璁颁綇瀵嗙爜"
+                   name="agree"
+                   usedAlone
+                   v-model:checked="rememberPassword">
+      </up-checkbox>
+    </view>
   </view>
 </template>
 
 <script setup>
-import modal from '@/plugins/modal'
-import { userLoginFacotryList} from '@/api/login'
-import { ref, onMounted } from "vue";
-import useUserStore from '@/store/modules/user'
-import { getWxCode } from '@/utils/geek';
-import { wxLogin } from '@/api/oauth';
-import { setToken } from '@/utils/auth';
-const userStore = useUserStore()
-const useWxLogin = ref(false); // 鏄惁浣跨敤寰俊鐧诲綍
-const rememberPassword = ref(false); // 璁颁綇瀵嗙爜
-const loginForm = ref({
-  username: "",
-  password: "",
-	factoryId: "",
-	currentFatoryName: "",
-});
-const factoryList = ref([]) // 鍏徃鍒楄〃
+  import { modal } from "@/plugins";
 
-// 淇濆瓨瀵嗙爜鍒版湰鍦板瓨鍌�
-function savePassword() {
-  if (rememberPassword.value) {
-    uni.setStorageSync('remembered_username', loginForm.value.username);
-    uni.setStorageSync('remembered_password', loginForm.value.password);
-    uni.setStorageSync('remember_password', true);
-  } else {
-    uni.removeStorageSync('remembered_username');
-    uni.removeStorageSync('remembered_password');
-    uni.setStorageSync('remember_password', false);
-  }
-}
+  const showToast = message => {
+    uni.showToast({
+      title: message,
+      icon: "none",
+    });
+  };
+  import { userLoginFacotryList, updateClientId } from "@/api/login";
+  import { ref, onMounted } from "vue";
+  import useUserStore from "@/store/modules/user";
+  import { getWxCode } from "@/utils/geek";
+  import { wxLogin } from "@/api/oauth";
+  import { setToken } from "@/utils/auth";
+  import View from "@/pages/procurementManagement/procurementLedger/view.vue";
+  const userStore = useUserStore();
+  const useWxLogin = ref(false); // 鏄惁浣跨敤寰俊鐧诲綍
+  const rememberPassword = ref(false); // 璁颁綇瀵嗙爜
+  const loginForm = ref({
+    userName: "",
+    password: "",
+    currentFatoryName: "",
+  });
+  const factoryList = ref([]); // 鍏徃鍒楄〃
 
-// 浠庢湰鍦板瓨鍌ㄥ姞杞藉瘑鐮�
-function loadPassword() {
-  const remembered = uni.getStorageSync('remember_password');
-  if (remembered) {
-    rememberPassword.value = true;
-    const savedUsername = uni.getStorageSync('remembered_username');
-    const savedPassword = uni.getStorageSync('remembered_password');
-    if (savedUsername) {
-      loginForm.value.username = savedUsername;
-    }
-    if (savedPassword) {
-      loginForm.value.password = savedPassword;
+  // 淇濆瓨瀵嗙爜鍒版湰鍦板瓨鍌�
+  function savePassword() {
+    if (rememberPassword.value) {
+      uni.setStorageSync("remembered_username", loginForm.value.userName);
+      uni.setStorageSync("remembered_password", loginForm.value.password);
+      uni.setStorageSync("remember_password", true);
+    } else {
+      uni.removeStorageSync("remembered_username");
+      uni.removeStorageSync("remembered_password");
+      uni.setStorageSync("remember_password", false);
     }
   }
-}
 
-if (useWxLogin.value) {
-  getWxCode().then(res => {
-    console.log(res);
-    wxLogin('miniapp',res).then(res => {
-      if(res.token != null){
-        setToken(res.token);
-        loginSuccess()
+  // 浠庢湰鍦板瓨鍌ㄥ姞杞藉瘑鐮�
+  function loadPassword() {
+    const remembered = uni.getStorageSync("remember_password");
+    if (remembered) {
+      rememberPassword.value = true;
+      const savedUsername = uni.getStorageSync("remembered_username");
+      const savedPassword = uni.getStorageSync("remembered_password");
+      if (savedUsername) {
+        loginForm.value.userName = savedUsername;
       }
-    });
-  })
-}
-
-function getUserLoginFacotryList() {
-	if(loginForm.value.username){
-		userLoginFacotryList({userName:loginForm.value.username}).then(res => {
-			// 妫�鏌es.data鏄惁涓烘暟缁�
-			if (res.data && Array.isArray(res.data)) {
-				// 閲嶆柊缁勮鏁版嵁鏍煎紡锛歞eptId鍙樻垚id锛宒eptName鍙樻垚name
-				factoryList.value = res.data.map(item => ({
-					id: item.deptId,
-					name: item.deptName
-				}))
-			} else {
-				// 濡傛灉res.data涓嶆槸鏁扮粍锛岃缃负绌烘暟缁�
-				factoryList.value = []
-			}
-		}).catch(error => {
-			modal.msgError('鑾峰彇鍏徃鍒楄〃澶辫触:', error)
-			factoryList.value = []
-		})
-	}else {
-		factoryList.value = []
-	}
-}
-
-async function handleLogin() {
-  if (loginForm.value.username === "") {
-    modal.msgError("璇疯緭鍏ユ偍鐨勮处鍙�")
-  } else if (loginForm.value.password === "") {
-    modal.msgError("璇疯緭鍏ユ偍鐨勫瘑鐮�")
-  } else if (loginForm.value.factoryId === "") {
-    modal.msgError("璇烽�夋嫨鍏徃")
-  } else {
-    modal.loading("鐧诲綍涓紝璇疯�愬績绛夊緟...")
-    pwdLogin()
+      if (savedPassword) {
+        loginForm.value.password = savedPassword;
+      }
+    }
   }
-};
-// 瀵嗙爜鐧诲綍
-async function pwdLogin() {
-  userStore.loginCheckFactory(loginForm.value).then(() => {
-    modal.closeLoading()
-    // 鐧诲綍鎴愬姛鍚庝繚瀛樺瘑鐮�
-    savePassword();
-    loginSuccess()
-  }).catch(() => {
-		modal.closeLoading()
-  })
-};
 
-function loginSuccess(result) {
-  // 璁剧疆鐢ㄦ埛淇℃伅
-  userStore.getInfo().then(res => {
-    uni.switchTab({
-      url: '/pages/index'
+  if (useWxLogin.value) {
+    getWxCode().then(res => {
+      console.log(res);
+      wxLogin("miniapp", res).then(res => {
+        if (res.token != null) {
+          setToken(res.token);
+          loginSuccess();
+        }
+      });
     });
-  })
-}
-// 椤甸潰鍔犺浇鏃舵鏌ユ槸鍚︽湁淇濆瓨鐨勫瘑鐮�
-onMounted(() => {
-	loadPassword();
-	getUserLoginFacotryList()
-});
+  }
+
+  function getUserLoginFacotryList() {
+    if (loginForm.value.userName) {
+      userLoginFacotryList({ userName: loginForm.value.userName })
+        .then(res => {
+          console.log("res", res);
+          // 妫�鏌es.data鏄惁涓烘暟缁�
+          if (res.data && Array.isArray(res.data)) {
+            // 閲嶆柊缁勮鏁版嵁鏍煎紡锛歞eptId鍙樻垚id锛宒eptName鍙樻垚name
+            factoryList.value = res.data.map(item => ({
+              id: item.deptId,
+              name: item.deptName,
+            }));
+          } else {
+            // 濡傛灉res.data涓嶆槸鏁扮粍锛岃缃负绌烘暟缁�
+            factoryList.value = [];
+          }
+        })
+        .catch(error => {
+          showToast("鑾峰彇鍏徃鍒楄〃澶辫触:", error);
+          factoryList.value = [];
+        });
+    } else {
+      factoryList.value = [];
+    }
+  }
+
+  async function handleLogin() {
+    if (loginForm.value.userName === "") {
+      showToast("璇疯緭鍏ユ偍鐨勮处鍙�");
+    } else if (loginForm.value.password === "") {
+      showToast("璇疯緭鍏ユ偍鐨勫瘑鐮�");
+    } else {
+      showToast("鐧诲綍涓紝璇疯�愬績绛夊緟...");
+      pwdLogin();
+    }
+  }
+  // 瀵嗙爜鐧诲綍
+  async function pwdLogin() {
+    userStore
+      .loginCheckFactory(loginForm.value)
+      .then(() => {
+        modal.closeLoading();
+        // 鐧诲綍鎴愬姛鍚庝繚瀛樺瘑鐮�
+        savePassword();
+        loginSuccess();
+      })
+      .catch(() => {
+        modal.closeLoading();
+      });
+  }
+
+  function loginSuccess(result) {
+    // 璁剧疆鐢ㄦ埛淇℃伅
+    userStore.getInfo().then(res => {
+      // 鐧诲綍鎴愬姛鍚庯紝灏嗗鎴风鎺ㄩ�佹爣璇嗗彂閫佸埌鏈嶅姟鍣�
+      sendClientIdToServer();
+      uni.switchTab({
+        url: "/pages/index",
+      });
+    });
+  }
+
+  // 灏嗗鎴风鎺ㄩ�佹爣璇嗗彂閫佸埌鏈嶅姟鍣�
+  function sendClientIdToServer() {
+    // 鑾峰彇鏈湴瀛樺偍鐨勫鎴风鏍囪瘑
+    const clientId = uni.getStorageSync("clientid");
+    if (clientId) {
+      console.log("鐧诲綍鎴愬姛锛屽噯澶囧彂閫佸鎴风鏍囪瘑鍒版湇鍔″櫒:", clientId);
+      // 杩欓噷璋冪敤鍚庣鎺ュ彛鍙戦�佸鎴风鏍囪瘑
+      updateClientId({ cid: clientId })
+        .then(res => {
+          console.log("鏈嶅姟鍣ㄥ搷搴�:", res);
+          if (res.code === 200) {
+            console.log("瀹㈡埛绔爣璇嗗凡鎴愬姛鍙戦�佸埌鏈嶅姟鍣�");
+          } else {
+            console.log("鏈嶅姟鍣ㄨ繑鍥為敊璇�:", res.msg);
+          }
+        })
+        .catch(error => {
+          console.log("鍙戦�佸鎴风鏍囪瘑鍒版湇鍔″櫒澶辫触:", error);
+        });
+      // 绀轰緥锛歛pi.updateClientId({ clientId: clientId });
+      // 鐢变簬娌℃湁鍏蜂綋鐨勬帴鍙o紝杩欓噷鍙墦鍗版棩蹇�
+      console.log("瀹㈡埛绔爣璇嗗凡鍙戦�佸埌鏈嶅姟鍣�");
+    } else {
+      console.log("鏈幏鍙栧埌瀹㈡埛绔帹閫佹爣璇�");
+    }
+  }
+  // 椤甸潰鍔犺浇鏃舵鏌ユ槸鍚︽湁淇濆瓨鐨勫瘑鐮�
+  onMounted(() => {
+    loadPassword();
+    getUserLoginFacotryList();
+  });
 </script>
 
 <style lang="scss">
-page {
-  background-color: #ffffff;
-}
-
-.normal-login-container {
-  width: 100%;
-
-  .logo-content {
-    width: 100%;
-		font-weight: 400;
-		font-size: 30px;
-		color: #333333;
-		margin: 80px 0 0 30px;
-
-    image {
-      border-radius: 4px;
-    }
-
-    .title {
-      margin-left: 10px;
-    }
+  page {
+    background-color: #ffffff;
   }
-	.u-checkbox {
-		margin-left: 34px;
-	}
 
-  .login-form-content {
-    text-align: center;
-    margin: 58px auto;
-		padding: 0 30px;
+  .normal-login-container {
+    width: 100%;
+    height: 100vh;
 
-		.input-item {
-       margin: 30px auto;
-       height: 45px;
+    .logo-content {
+      width: 90%;
+      font-weight: 400;
+      font-size: 30px;
+      color: #333333;
+      margin: 80px 0 0 30px;
 
-       .icon {
-         font-size: 38rpx;
-         margin-left: 10px;
-         color: #999;
-       }
+      image {
+        border-radius: 4px;
+      }
 
-       .input {
-         width: 100%;
-         font-size: 14px;
-         line-height: 20px;
-         text-align: left;
-         padding-left: 15px;
-       }
-     }
-		.select-container {
-			flex: 1;
-			border-bottom: 1px solid #e5e5e5;
-			padding: 6px 9px;
-			
-			:deep(.up-select) {
-				border: none;
-				background: transparent;
-				
-				.up-select__label {
-					font-size: 14px;
-					color: #333;
-				}
-				
-				.up-select__value {
-					font-size: 14px;
-					color: #333;
-				}
-			}
-		}
-
-    .login-btn {
-      margin-top: 60px;
-      height: 50px;
-			background: linear-gradient( 140deg, #00BAFF 0%, #006CFB 100%);
-			box-shadow: 0px 4px 10px 0px rgba(3,88,185,0.2);
-			border-radius: 40px 40px 40px 40px;
-    }
-
-    .xieyi {
-      color: #333;
-      margin-top: 20px;
-    }
-
-    .login-code {
-      height: 38px;
-      float: right;
-
-      .login-code-img {
-        height: 38px;
-        position: absolute;
+      .title {
         margin-left: 10px;
-        width: 200rpx;
+      }
+    }
+    .u-checkbox {
+      margin-left: 34px;
+    }
+
+    .login-form-content {
+      text-align: center;
+      margin: 58px auto;
+      padding: 0 30px;
+
+      .input-item {
+        margin: 30px auto;
+        height: 45px;
+
+        .icon {
+          font-size: 38rpx;
+          margin-left: 10px;
+          color: #999;
+        }
+
+        .input {
+          width: 100%;
+          font-size: 14px;
+          line-height: 20px;
+          text-align: left;
+          padding-left: 15px;
+        }
+      }
+      .select-container {
+        flex: 1;
+        border-bottom: 1px solid #e5e5e5;
+        padding: 6px 9px;
+
+        :deep(.up-select) {
+          border: none;
+          background: transparent;
+
+          .up-select__label {
+            font-size: 14px;
+            color: #333;
+          }
+
+          .up-select__value {
+            font-size: 14px;
+            color: #333;
+          }
+        }
+      }
+
+      .login-btn {
+        margin-top: 60px;
+        height: 50px;
+        background: linear-gradient(140deg, #00baff 0%, #006cfb 100%);
+        box-shadow: 0px 4px 10px 0px rgba(3, 88, 185, 0.2);
+        border-radius: 40px 40px 40px 40px;
+      }
+
+      .xieyi {
+        color: #333;
+        margin-top: 20px;
+      }
+
+      .login-code {
+        height: 38px;
+        float: right;
+
+        .login-code-img {
+          height: 38px;
+          position: absolute;
+          margin-left: 10px;
+          width: 200rpx;
+        }
       }
     }
   }
-}
 </style>

--
Gitblit v1.9.3