Explorar el Código

登录记住账号本地加密储存

wxy hace 4 meses
padre
commit
08847a7610

+ 12 - 2
src/api/path/tariffManagement.api.js

@@ -21,7 +21,17 @@ export function deleteTariff(params) {
     return service.get('/admin/platform/deleteTariff', { params })
 }
 
-// 资费计划详情
-export function getTariffList(params) {
+// 添加资费套餐
+export function addTariffPackage(data) {
+  return service.post('/admin/platform/addTariffProduct', data)
+}
+
+// 查询资费商品
+export function CheckTariffPackages(params){
+    return service.get('/admin/platform/tariffProductList', {params})
+}
 
+// 更新资费商品
+export function UpdateTariffTtems(data){
+    return service.post('/admin/platform/updateTariffProduct', data)
 }

+ 44 - 0
src/store/modules/Login.js

@@ -0,0 +1,44 @@
+import { defineStore } from "pinia";
+import CryptoJS from "crypto-js";
+
+// 登录
+export const FormLoginUser = defineStore({
+  id: "FormLoginUser",
+  state: () => ({
+    encryptedUsername: "",
+    encryptedPassword: "",
+    SECRET_KEY: "your-secret-key",
+  }),
+  getters: {
+    // 使用 RC4 加密
+  },
+  actions: {
+    // 登录时加密并保存
+    loginYester(data) {
+      const encryptedData = this.encryptData(data);
+      localStorage.setItem("USER_KEY_ACCOUT", encryptedData);
+    },
+
+    // 加载加密后的账户信息
+    loadCredentials() {
+        const encryptedData = localStorage.getItem("USER_KEY_ACCOUT") || false;
+      if (encryptedData) {
+        return this.decryptData(encryptedData);
+      }
+      return null;
+    },
+    encryptData(data) {
+      const jsonString = JSON.stringify(data);
+      // 使用 RC4 加密
+      return CryptoJS.RC4.encrypt(jsonString, this.SECRET_KEY).toString();
+    },
+    // 解密数据
+    decryptData(encryptedData) {
+      // 解密 RC4 数据
+      const bytes = CryptoJS.RC4.decrypt(encryptedData, this.SECRET_KEY);
+      // 将解密后的结果转换为字符串并解析为对象
+      const decryptedData = bytes.toString(CryptoJS.enc.Utf8);
+      return JSON.parse(decryptedData); // 解析为对象
+    },
+  },
+});

+ 39 - 26
src/views/login/login-form.vue

@@ -5,18 +5,18 @@
 
     <a-form ref="loginForm" :model="formData" class="login-form" @submit-success="handleSubmit">
       <a-form-item field="username" :rules="[{ required: true, message: '用户名不能为空' }]"
-                   :validate-trigger="['change', 'blur']" hide-label>
+        :validate-trigger="['change', 'blur']" hide-label>
         <a-input v-model="formData.username" placeholder="用户名:">
           <template #prefix>
-            <icon-user/>
+            <icon-user />
           </template>
         </a-input>
       </a-form-item>
       <a-form-item field="password" :rules="[{ required: true, message: '密码不能为空' }]"
-                   :validate-trigger="['change', 'blur']" hide-label>
+        :validate-trigger="['change', 'blur']" hide-label>
         <a-input-password v-model="formData.password" placeholder="密码:" allow-clear>
           <template #prefix>
-            <icon-lock/>
+            <icon-lock />
           </template>
         </a-input-password>
       </a-form-item>
@@ -24,7 +24,7 @@
 
       <a-space :size="16" direction="vertical">
         <div class="login-form-password-actions">
-          <a-checkbox checked="rememberPassword" :default-checked="true" @change="setRememberPassword">
+          <a-checkbox v-model="rememberPassword">
             记住账号
           </a-checkbox>
           <!-- <a-link>忘记密码</a-link> -->
@@ -36,28 +36,41 @@
 </template>
 
 <script setup>
-import {ref, reactive} from 'vue'
-import {encryptByDES} from "@/utils"
-import {loginApi} from "@/api/path/login.api"
-import {useSystemStore} from "@/store/modules/systemStore"
-import {useRouter} from 'vue-router'
-import {updateRouteByMenu} from '@/router/router.update'
-
+import { ref, reactive, toRefs, onMounted } from 'vue'
+import { encryptByDES } from "@/utils"
+import { loginApi } from "@/api/path/login.api"
+import { useSystemStore } from "@/store/modules/systemStore"
+import { useRouter } from 'vue-router'
+import { updateRouteByMenu } from '@/router/router.update'
+import { FormLoginUser } from '@/store/modules/Login'
 const router = useRouter()
-const formData = ref({
-  username: localStorage.remember_user_name
+const systemStore = useSystemStore()
+const LoginSet = FormLoginUser()
+const state = ref({
+  formData: {
+    username: '',
+    password: ''
+  },
+  formLoading: false,
+  rememberPassword: false,
 })
-const formLoading = ref(false)
-const rememberPassword = ref(true)
 
-const systemStore = useSystemStore()
+const { formData, formLoading, rememberPassword } = toRefs(state.value)
 
 const handleSubmit = async () => {
-  const {data} = await loginApi({
+  const { data } = await loginApi({
     username: formData.value.username,
     password: encryptByDES(formData.value.password)
   })
-  window.localStorage.setItem('remember_user_name', formData.value.username)
+
+  if (rememberPassword.value) {
+    LoginSet.loginYester(formData.value)
+  } else {
+    const nste = localStorage.getItem("USER_KEY_ACCOUT") || false;
+    if (nste) {
+      localStorage.removeItem('USER_KEY_ACCOUT')
+    }
+  }
 
   systemStore.setStateValue({
     key: 'token',
@@ -71,21 +84,21 @@ const handleSubmit = async () => {
   })
   systemStore.setStateValue({
     key: 'role',
-    value: data.user_type,
+    value: data.userType,
     localStorage: true,
   })
   await updateRouteByMenu(router, systemStore)
   router.push({
-    path: "/",
+    path: "/system-menu",
   })
-
 }
 
-const setRememberPassword = (e) => {
-  if (!e) {
-    window.localStorage.removeItem('remember_user_name')
+onMounted(() => {
+  if (LoginSet.loadCredentials()) {
+    formData.value.username = LoginSet.loadCredentials()?.username
+    formData.value.password = LoginSet.loadCredentials()?.password
   }
-}
+})
 
 
 </script>

+ 1 - 1
src/views/order/BuyCard/Card.vue

@@ -61,7 +61,7 @@ const props = defineProps({
 const modelValue = toRef(props, 'modelValue')
 const emit = defineEmits(['update:modelValue', 'submit'])
 const state = ref({
-    userName: localStorage.getItem('remember_user_name'),
+    userName: localStorage.getItem('user_login_information')?.username,
     userType: JSON.parse(localStorage.getItem('user_login_information'))?.userType, // 1平台 2用户
     showAudit: false,
     formRef: null,

+ 1 - 1
src/views/order/BuyCard/index.vue

@@ -85,7 +85,7 @@ import Search from '@/components/Search/index.vue'
 import returnCard from './returnCard.vue'
 // 数据层
 const state = ref({
-  userName: localStorage.getItem('remember_user_name'),
+  userName: localStorage.getItem('user_login_information')?.username,
   userType: JSON.parse(localStorage.getItem('user_login_information'))?.userType, // 1平台 2用户
   tableData: [],
   currentIndex: null,

+ 61 - 15
src/views/tariffManagement/Management/meal.vue

@@ -1,5 +1,5 @@
 <template>
-    <a-modal width="50%" v-model:visible="modelValue" @ok="handleOk" @cancel="handleCancel" title="套餐">
+    <a-modal width="55%" v-model:visible="modelValue" @ok="handleOk" @cancel="handleCancel" title="套餐">
         <div class="add"><a-button type="primary" @click="addMeal">添加套餐</a-button></div>
         <div class="item_warp">
             <div v-for="(item, index) in wanberFloter">
@@ -9,14 +9,14 @@
                     </template>
                     <div class="Form">
                         <a-form :model="item" auto-label-width :rules="rules" ref="formRef">
-                            <a-form-item field="PackageTerm" label="套餐期限">
-                                <a-input v-model="item.PackageTerm" placeholder="请输入" />
+                            <a-form-item field="period" label="套餐期限(月)" v-if="role.getRole == 1">
+                                <a-input v-model="item.period" placeholder="请输入" />
                             </a-form-item>
-                            <a-form-item field="PackagePrice" label="套餐价格">
-                                <a-input v-model="item.PackagePrice" placeholder="请输入" />
+                            <a-form-item field="price" label="套餐价格">
+                                <a-input v-model="item.price" placeholder="请输入" />
                             </a-form-item>
-                            <a-form-item field="Pricing" label="币种">
-                                <a-select v-model="item.pricing" :style="{ width: '320px' }" placeholder="请选择币种">
+                            <a-form-item field="currency" label="币种" v-if="role.getRole == 1">
+                                <a-select v-model="item.currency" :style="{ width: '320px' }" placeholder="请选择币种">
                                     <a-option v-for="res of Pricing" :value="res.value" :label="res.label" />
                                 </a-select>
                             </a-form-item>
@@ -31,36 +31,69 @@
 <script setup>
 import { ref, onMounted, toRefs, toRef, watch } from 'vue';
 import { Getdictionary } from '@/mixins/index.js'
+import { useSystemStore } from '@/store/modules/systemStore'
+import { Message } from '@arco-design/web-vue'
+import { addTariffPackage, CheckTariffPackages,UpdateTariffTtems } from '@/api/path/tariffManagement.api'
 const props = defineProps({
     modelValue: {
         type: Boolean,
         default: false
     },
+    traffIds: {
+        type: [String, Number],
+        default: null
+    }
 })
-
+const role = useSystemStore()
 const modelValue = toRef(props, 'modelValue')
+const traffIds = toRef(props, 'traffIds')
+const indexSet = ref(0)
 const emit = defineEmits(['update:modelValue', 'submit'])
 const rules = {
-    PackageTerm: [{ required: true, trigger: 'change', }],
-    PackagePrice: [{ required: true, trigger: 'change', }],
-    pricing: [{ required: true, trigger: 'change', }],
+    period: [{ required: true, trigger: 'change', }],
+    price: [{ required: true, trigger: 'change', }],
+    currency: [{ required: true, trigger: 'change', }],
 }
 const state = ref({
     wanberFloter: [
-        { PackageTerm: '', PackagePrice: '', pricing: '' }
+        { id: '', period: '', price: '', currency: '' }
     ],
     formRef: null,
     Pricing: []
 })
 const { wanberFloter, formRef, Pricing } = toRefs(state.value)
+// 添加套餐
 const handleOk = () => {
-    emit('update:modelValue', false)
+    if (indexSet.value === 0) {
+        // 添加
+        addTariffPackage({ tariffId: traffIds.value, list: wanberFloter.value }).then(res => {
+            if (res.code === 200) {
+                Message.success('添加成功')
+                emit('update:modelValue', false)
+                emit('submit', true)
+                handleCancel()
+            }
+        })
+    } else {
+        // 修改
+        UpdateTariffTtems(wanberFloter.value).then(res=>{
+            if(res.code === 200){
+                Message.success('修改成功')
+                emit('update:modelValue', false)
+                emit('submit', true)
+                handleCancel()
+            }
+        })
+    }
 }
 const handleCancel = () => {
     emit('update:modelValue', false)
+    wanberFloter.value = [
+        { id: '', period: '', price: '', currency: '' }
+    ]
 }
 const addMeal = () => {
-    wanberFloter.value.push({ PackageTerm: '', PackagePrice: '', SetSize: '' })
+    wanberFloter.value.push({ id: '', period: '', price: '', currency: '' })
 }
 const deletaMeal = (index) => {
     if (wanberFloter.value.length !== 1) {
@@ -72,6 +105,18 @@ const handeDict = async () => {
     Pricing.value = await Getdictionary('currencyType')
 }
 
+watch(() => traffIds.value, val => {
+    if (!val) return
+    CheckTariffPackages({ tariffId: val }).then(res => {
+        if (res.code === 200) {
+            indexSet.value = res.data.length
+            if (res.data.length !== 0) {
+                wanberFloter.value = res.data
+            }
+        }
+    })
+})
+
 onMounted(() => {
     handeDict()
 })
@@ -86,6 +131,7 @@ onMounted(() => {
     margin-top: 20px;
     display: flex;
     flex-wrap: wrap;
-    gap: 15px;
+    gap: 10px;
+    justify-content: space-between;
 }
 </style>

+ 7 - 7
src/views/tariffManagement/customer/index.vue

@@ -80,19 +80,19 @@ const {t} = useI18n();
 const loading = ref(false);
 
 const columns = computed(() => [
-  {title: t('customer.id'), dataIndex: 'id',width: 100},
+  {title: t('customer.id'), dataIndex: 'id',ellipsis:true},
   // {title: t('customer.customerCode'), dataIndex: 'customerCode'},
-  {title: t('customer.customerName'), dataIndex: 'name',width: 120},
+  {title: t('customer.customerName'), dataIndex: 'name',ellipsis:true},
   {title: t('customer.userAdmin'), dataIndex: 'username'},
   // {title: t('customer.accountBalance'), dataIndex: 'accountBalance'},
   // {title: t('customer.paymentMethodName'), dataIndex: 'paymentMethod'},
-  {title: t('customer.customerStatus'), slotName: 'state',width: 130},
+  {title: t('customer.customerStatus'), slotName: 'state',ellipsis:true},
   // {title: t('customer.validPeriod'), dataIndex: 'validPeriod'},
   // {title: t('customer.activeCards'), dataIndex: 'activeCards'},
-  {title: t('customer.userTypeName'), dataIndex: 'userType',width: 100},
-  {title: t('customer.startTime'), dataIndex: 'createdAt',width: 200},
-  {title: t('customer.updateTime'), dataIndex: 'updatedAt',width: 200},
-  {title: t('global.common.operations'), slotName: 'operation', width: 150},
+  {title: t('customer.userTypeName'), dataIndex: 'userType',ellipsis:true},
+  {title: t('customer.startTime'), dataIndex: 'createdAt',ellipsis:true},
+  {title: t('customer.updateTime'), dataIndex: 'updatedAt',ellipsis:true},
+  {title: t('global.common.operations'), slotName: 'operation', ellipsis:true},
 ]);
 
 onMounted(() => {

+ 8 - 5
src/views/tariffManagement/index.vue

@@ -57,7 +57,7 @@
         <a class="a-link" href="javascript:;" style="margin-right: 1rem" @click="dictShowModel(2, record)">{{
           $t('form.Edit')
         }}</a>
-        <a class="a-link" href="javascript:;" style="margin-right: 1rem" @click="meal(2, record)">套餐</a>
+        <a class="a-link" href="javascript:;" style="margin-right: 1rem" @click="meal(record)">套餐</a>
         <!-- 删除 -->
         <a-popconfirm :content="$t('form.Delete')" :ok-text="$t('form.Confirm')" :cancel-text="$t('form.Cancel')"
           @ok="handleDel(record.id)">
@@ -93,7 +93,7 @@
 
     </a-modal>
 
-    <Meal v-model:model-value="modealShow" />
+    <Meal v-model:model-value="modealShow" :traffIds="ids" @submit="intData()"/>
     <Add v-model:model-value="visible" :type-index="typeCurrent" :FormDataList="FormDataList" @submit="intData()"></Add>
   </div>
 </template>
@@ -134,7 +134,8 @@ const state = ref({
     type: 'radio',
     showCheckedAll: true,
     onlyCurrent: false,
-  }
+  },
+  ids:null
 })
 const {
   searchForm,
@@ -151,7 +152,8 @@ const {
   planVisible,
   formData,
   selectedKeysPlan,
-  rowSelectionPlan
+  rowSelectionPlan,
+  ids
 } = toRefs(state.value);
 
 const intData = async () => {
@@ -239,7 +241,8 @@ const handleDictValue = async () => {
   currency.value = await Getdictionary('currencyType')
 }
 
-const meal = () => {
+const meal = (data) => {
+  ids.value = data.id
   modealShow.value = true
 }