Commit 8a6013ce authored by chenqikuai's avatar chenqikuai

push some code

parents
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
{
"recommendations": ["johnsoncodehk.volar"]
}
# Vue 3 + Typescript + Vite
This template should help get you started developing with Vue 3 and Typescript in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
## Recommended IDE Setup
- [VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=johnsoncodehk.volar)
## Type Support For `.vue` Imports in TS
Since TypeScript cannot handle type information for `.vue` imports, they are shimmed to be a generic Vue component type by default. In most cases this is fine if you don't really care about component prop types outside of templates. However, if you wish to get actual prop types in `.vue` imports (for example to get props validation when using manual `h(...)` calls), you can enable Volar's `.vue` type support plugin by running `Volar: Switch TS Plugin on/off` from VSCode command palette.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"name": "source-trace-manage",
"private": true,
"version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "vue-tsc --noEmit && vite build",
"preview": "vite preview"
},
"dependencies": {
"axios": "^0.26.1",
"cqk-sy-ui": "^1.0.15",
"crypto-js": "^4.1.1",
"element-plus": "^2.1.4",
"js-md5": "^0.7.3",
"vue": "^3.2.25",
"vue-router": "^4.0.14"
},
"devDependencies": {
"@types/js-md5": "^0.4.3",
"@types/node": "^17.0.22",
"@vitejs/plugin-vue": "^2.2.0",
"typescript": "^4.5.4",
"vite": "^2.8.0",
"vue-tsc": "^0.29.8"
}
}
<script setup lang="ts">
</script>
<template>
<router-view></router-view>
</template>
<script setup lang="ts">
import { ref } from 'vue'
defineProps<{ msg: string }>()
const count = ref(0)
</script>
<template>
<h1>{{ msg }}</h1>
<p>
Recommended IDE setup:
<a href="https://code.visualstudio.com/" target="_blank">VSCode</a>
+
<a href="https://github.com/johnsoncodehk/volar" target="_blank">Volar</a>
</p>
<p>See <code>README.md</code> for more information.</p>
<p>
<a href="https://vitejs.dev/guide/features.html" target="_blank">
Vite Docs
</a>
|
<a href="https://v3.vuejs.org/" target="_blank">Vue 3 Docs</a>
</p>
<button type="button" @click="count++">count is: {{ count }}</button>
<p>
Edit
<code>components/HelloWorld.vue</code> to test hot module replacement.
</p>
</template>
<style scoped>
a {
color: #42b983;
}
label {
margin: 0 0.5em;
font-weight: bold;
}
code {
background-color: #eee;
padding: 2px 4px;
border-radius: 4px;
color: #304455;
}
</style>
/// <reference types="vite/client" />
declare module '*.vue' {
import type { DefineComponent } from 'vue'
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
const component: DefineComponent<{}, {}, any>
export default component
}
import { createApp } from "vue";
import App from "./App.vue";
import { router } from "./router";
import "cqk-sy-ui/style.css";
(window as any).global = window;
createApp(App).use(router).mount("#app");
import { createRouter, createWebHashHistory } from "vue-router";
const routes = [
// 宣传页
{
path: "/",
name: "home",
component: () => import("./views/Home.vue"),
},
// 登录
{
path: "/signIn",
name: "signIn",
component: () => import("./views/SignIn.vue"),
},
// {
// path: "/main",
// component: () => import(/* webpackChunkName: "main" */ "./views/Main.vue"),
// children: [
// {
// path: "/categoryManage",
// name: "categoryManage",
// component: () =>
// import(
// /* webpackChunkName: "categoryManage" */ "@/components/category/Index.vue"
// ),
// },
// {
// path: "/passManage",
// name: "passManage",
// component: () =>
// import(
// /* webpackChunkName: "categoryManage" */ "@/components/pass/Index.vue"
// ),
// redirect: "/passList",
// children: [
// {
// path: "/passList",
// name: "passList",
// component: () => import("@/components/pass/PassList.vue"),
// },
// {
// path: "/transferRecord",
// name: "transferRecord",
// component: () => import("@/components/pass/TransferRecord.vue"),
// },
// ],
// },
// // 个人中心
// {
// path: "/userCenter",
// name: "userCenter",
// component: () =>
// import(
// /* webpackChunkName: "userCenter" */ "@/views/userCenter/index.vue"
// ),
// },
// {
// path: "/choosePackage",
// name: "choosePackage",
// component: () =>
// import(
// /* webpackChunkName: "companyVerify" */ "@/views/userCenter/choosePackage.vue"
// ),
// },
// {
// path: "/initPassword",
// name: "initPassword",
// component: () =>
// import(
// /* webpackChunkName: "initPassword" */ "@/views/userCenter/SetPassword.vue"
// ),
// },
// {
// path: "/companyVerify",
// name: "companyVerify",
// component: () =>
// import(
// /* webpackChunkName: "companyVerify" */ "@/views/userCenter/CompanyVerify.vue"
// ),
// },
// {
// path: "/editPassword",
// name: "editPassword",
// component: () =>
// import(
// /* webpackChunkName: "editPassword" */ "@/views/userCenter/EditPassword.vue"
// ),
// },
// {
// path: "/editPhone",
// name: "editPhone",
// component: () =>
// import(
// /* webpackChunkName: "editPhone" */ "@/views/userCenter/EditPhone.vue"
// ),
// },
// {
// path: "/personVerify",
// name: "personVerify",
// component: () =>
// import(
// /* webpackChunkName: "personVerify" */ "@/views/userCenter/PersonVerify.vue"
// ),
// },
// {
// path: "/editTemplate",
// name: "editTemplate",
// component: () =>
// import(
// /* webpackChunkName: "editTemplate" */ "@/views/template/editTemplate.vue"
// ),
// },
// ],
// },
// {
// path: "/passMaker",
// name: "passMaker",
// component: () => import("@/views/pass/PassMaker.vue"),
// },
];
export const router = createRouter({
history: createWebHashHistory(),
routes,
});
import axios, { AxiosRequestConfig, AxiosResponse } from "axios";
import { ElMessage } from "element-plus";
import { getLoginCode } from "./storage";
export interface ResBase {
code: number;
data: any;
msg: string;
}
// get请求
export interface GetParam {
type: "get" | "delete";
url: string;
params?: { [key: string]: any };
header?: any;
config?: any;
}
// post请求
export interface PostParam {
type: "post" | "put" | "patch" | "delete";
url: string;
params?: any;
header?: any;
config?: any;
}
//获取对象的长度
function length(o: any) {
let count = 0;
for (const i in o) {
count++;
}
return count;
}
// ajax
async function $ajax(param: PostParam | GetParam) {
try {
const type = param.type.toLowerCase();
const result: AxiosRequestConfig = {
method: type,
url: param.url,
params: {},
headers: {
Authorization: "Bearer " + getLoginCode(),
...(param.header || {}),
},
...(param.config || {}),
};
if (param.params) {
if (["get"].includes(type)) {
let restfulUrl = param.url + `?`;
const params = (param as GetParam).params || [];
let num = length(params);
Object.keys(params).forEach(function (key) {
if (num === 1) {
restfulUrl += `${key}=${params[key]}`;
} else {
restfulUrl += `${key}=${params[key]}&`;
num--;
}
});
result.url = restfulUrl;
} else {
result.data = param.params;
}
}
// 返回res
const res: AxiosResponse<ResBase> = await axios(result);
if (res.data.code === 200) {
// mock 为 0
return res.data || {};
} else if (res.data.code == 403) {
ElMessage.warning("登录过期,请刷新页面");
sessionStorage.removeItem("user");
// router.push({ path: "/" });
// ?????? 跳转
return null;
} else {
ElMessage(res.data.msg);
return null;
}
} catch (e) {
if (axios.isCancel(e)) {
return null;
}
ElMessage.error("网络异常");
}
}
export { $ajax };
import CryptoJS from "crypto-js";
// 登录&&保存密码至本地
export function setLogin(
data: any,
params: {
login_type: number;
phone?: string;
email?: string;
pwd: string;
},
isAutoLogin: boolean
) {
// 0:手机号+密码 1:手机号+验证码 2:邮箱+密码 3:邮箱验+证码
if (params && isAutoLogin) {
localStorage.ciphertext = CryptoJS.AES.encrypt(
JSON.stringify(params),
"secret key 123"
);
}
// 清除之前保存的本地密码
if (!isAutoLogin && localStorage.ciphertext) {
localStorage.removeItem("ciphertext");
}
// 用于引导页
if (!localStorage.getItem("bootPage"))
localStorage.setItem("bootPage", "show"); // 如果不存在,就存入本地存储
// 保存token至本地
sessionStorage.setItem(`user`, JSON.stringify(data));
}
// 获取token
export function getLoginCode() {
if (
sessionStorage.getItem("user") &&
JSON.parse(String(sessionStorage.getItem("user"))).token
) {
return JSON.parse(String(sessionStorage.getItem("user"))).token;
} else {
return null;
}
}
<template>
<TracePage @navigate="$router.push" @search-hash="searchHash"></TracePage>
</template>
<script lang="ts" setup>
import { TracePage } from "cqk-sy-ui"
const CHAIN_BROWSER_URL_PREFIX = '';
const searchHash = (hashText: string) => {
if (hashText.trim() === "") {
window.open(CHAIN_BROWSER_URL_PREFIX);
} else {
window.open(
CHAIN_BROWSER_URL_PREFIX +
"product?hash=" +
hashText
);
}
}
</script>
\ No newline at end of file
<template>
<TraceLoginPage
:set-pwd="setPwd"
:handle-login="handleLogin"
:send-verification-code="sendVerificationCode"
></TraceLoginPage>
</template>
<script lang="ts" setup>
import { TraceLoginPage, GO_URLS } from "cqk-sy-ui"
import { iSendVerificationCode, iHandleLogin, iSetPwd } from "cqk-sy-ui/sy/pages/TraceLoginPage/types"
import { ElMessage } from "element-plus"
import { $ajax } from "@/service/index"
import * as storage from "@/service/storage"
import md5 from 'js-md5'
import { router } from "@/router"
const setPwd: iSetPwd = async (setPwdType, accountType, account, code, pwd) => {
let data = {};
if (accountType === 'email') {
data = {
email: account,
pwd: md5(
String(pwd) +
md5(String(pwd.length))
),
code: code,
code_type: 1,
};
} else {
data = {
phone: account,
pwd: md5(
String(pwd) +
md5(String(pwd.length))
),
code: code,
code_type: 0,
};
}
const res = await $ajax({
type: "post",
url: GO_URLS.setPwd,
params: data,
});
if (res) {
var message = "";
if (setPwdType === 'setPwd') {
message = "密码设置成功";
} else if (setPwdType === 'resetPwd') {
message = "密码重置成功";
}
ElMessage({
message: message,
type: "success",
});
}
return true;
}
const handleLogin: iHandleLogin = async (accountType, account, verificationMethod, verificationStr, remember) => {
if (accountType === 'email') {
let params = {};
if (verificationMethod === 'code') {
params = {
login_type: 3,
email: account,
code: verificationStr,
};
} else {
params = {
login_type: 2,
email: account,
pwd: md5(
String(verificationStr) + md5(String(verificationStr.length))
)
};
}
const res = await $ajax({
type: "post",
url: GO_URLS.login,
params: params,
});
if (res && res.data) {
sessionStorage.setItem("login_type", '2');
if (accountType === 'email') {
storage.setLogin(
res.data,
{
login_type: 2,
email: account,
pwd: verificationMethod,
},
remember || false
);
}
router.push({ path: "/categoryManage" });
return true;
} else {
return false;
}
} else if (accountType === 'phone') {
let params = {};
if (verificationMethod === 'code') {
params = {
login_type: 1,
phone: account,
code: verificationStr,
};
} else {
params = {
login_type: 0,
phone: account,
pwd: md5(
String(verificationStr) + md5(String(verificationStr.length))
),
};
}
const res = await $ajax({
type: "post",
url: GO_URLS.login,
params: params,
});
if (res && res.data) {
sessionStorage.setItem("login_type", '1');
storage.setLogin(
res.data,
{
login_type: 0,
phone: account,
pwd: verificationStr,
},
remember || false
);
router.push({ path: "/categoryManage" });
return true;
} else {
return false;
}
} else {
return false;
}
}
const sendVerificationCode: iSendVerificationCode = async (accountType, account, usedFor) => {
let res = null as any;
if (usedFor === 'login') {
if (accountType === 'phone') {
res = await $ajax({
type: "post",
url: GO_URLS.sendSms,
params: {
phone: account,
template_id: 0,
},
});
} else if (accountType === 'email') {
res = await $ajax({
url: GO_URLS.sendEmail,
type: "post",
params: {
email: account,
template_id: 0,
},
});
}
} else if (usedFor === 'setpwd') {
if (accountType === 'phone') {
res = await $ajax({
type: "post",
url: GO_URLS.sendSms,
params: {
phone: account,
template_id: 1,
},
});
} else if (accountType === 'email') {
res = await $ajax({
url: GO_URLS.sendEmail,
type: "post",
params: {
email: account,
template_id: 1,
},
});
}
}
if (res) {
ElMessage({
message: "短信已发送",
type: "success",
});
return true;
} else return false;
}
</script>
\ No newline at end of file
{
"compilerOptions": {
"target": "esnext",
"useDefineForClassFields": true,
"module": "esnext",
"moduleResolution": "node",
"strict": true,
"jsx": "preserve",
"sourceMap": true,
"baseUrl": ".",
"resolveJsonModule": true,
"esModuleInterop": true,
"lib": ["esnext", "dom"],
"paths": {
"@/*": ["./src/*"]
}
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
"references": [{ "path": "./tsconfig.node.json" }]
}
{
"compilerOptions": {
"composite": true,
"module": "esnext",
"moduleResolution": "node"
},
"include": ["vite.config.ts"]
}
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { resolve } from "path";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [vue()],
resolve: {
alias: {
// vue: resolve(`./node_modules/vue`),
"@": resolve("./src"),
},
},
server: {
proxy: {
"^/api": {
target: "http://121.37.141.165:46790/",
changeOrigin: true,
},
},
},
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment