From 86ab52df57838350a45ca7ef45bc6b15ff1f69ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A9=99=E5=AD=90?= <454313500@qq.com> Date: Wed, 13 Oct 2021 16:44:15 +0800 Subject: [PATCH] =?UTF-8?q?=E9=85=8D=E5=90=88=E5=89=8D=E5=90=8E=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/AccountController.cs | 90 +++++++ .../Controllers/UserController.cs | 11 + .../Yi.Framework.Common/Helper/EmailHelper.cs | 125 +++++++++ .../Helper/RandomHelper.cs | 99 ++++++++ Yi.Vue/package-lock.json | 10 + Yi.Vue/package.json | 4 +- Yi.Vue/src/api/accountApi.js | 39 +++ Yi.Vue/src/api/actionApi.js | 30 +++ Yi.Vue/src/api/fileApi.js | 16 ++ Yi.Vue/src/api/roleApi.js | 50 ++++ Yi.Vue/src/api/userApi.js | 101 ++++++++ Yi.Vue/src/assets/login.svg | 1 + Yi.Vue/src/layouts/login/LayoutLogin.vue | 65 +++++ Yi.Vue/src/main.js | 2 + Yi.Vue/src/router/index.js | 32 ++- Yi.Vue/src/store/index.js | 18 ++ Yi.Vue/src/store/modules/home.js | 42 ++++ Yi.Vue/src/store/modules/loader.js | 34 +++ Yi.Vue/src/store/modules/theme.js | 33 +++ Yi.Vue/src/store/modules/user.js | 122 +++++++++ Yi.Vue/src/views/login.vue | 163 ++++++++++++ Yi.Vue/src/views/register.vue | 238 ++++++++++++++++++ 22 files changed, 1319 insertions(+), 6 deletions(-) create mode 100644 Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs create mode 100644 Yi.Framework/Yi.Framework.Common/Helper/EmailHelper.cs create mode 100644 Yi.Framework/Yi.Framework.Common/Helper/RandomHelper.cs create mode 100644 Yi.Vue/src/api/accountApi.js create mode 100644 Yi.Vue/src/api/actionApi.js create mode 100644 Yi.Vue/src/api/fileApi.js create mode 100644 Yi.Vue/src/api/roleApi.js create mode 100644 Yi.Vue/src/api/userApi.js create mode 100644 Yi.Vue/src/assets/login.svg create mode 100644 Yi.Vue/src/layouts/login/LayoutLogin.vue create mode 100644 Yi.Vue/src/store/index.js create mode 100644 Yi.Vue/src/store/modules/home.js create mode 100644 Yi.Vue/src/store/modules/loader.js create mode 100644 Yi.Vue/src/store/modules/theme.js create mode 100644 Yi.Vue/src/store/modules/user.js create mode 100644 Yi.Vue/src/views/login.vue create mode 100644 Yi.Vue/src/views/register.vue diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs new file mode 100644 index 00000000..78a8d044 --- /dev/null +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs @@ -0,0 +1,90 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Yi.Framework.Common; +using Yi.Framework.Common.Models; +using Yi.Framework.Interface; +using Yi.Framework.Model.Models; + +namespace Yi.Framework.ApiMicroservice.Controllers +{ + [ApiController] + [Route("api/[controller]/[action]")] + public class AccountController : Controller + { + private readonly ILogger _logger; + + private IUserService _userService; + public AccountController(ILogger logger, IUserService userService) + { + _logger = logger; + _userService = userService; + } + + + /// + /// 登录方法,要返回data:{user,token} token先写123456789,不要有导航属性 + /// + /// + /// + [HttpPost] + public async Task Login(user _user) + { + } + + /// + /// 不用写,单纯制作日志 + /// + /// + [HttpPost] + public Result Logout() + { + return Result.Success(); + } + + /// + /// code为验证码,判断一下,假装验证码都是对的 + /// + /// + /// + /// + [HttpPost] + public async Task Register(user _user, string code) + { + + } + + /// + /// 传入邮箱,需要先到数据库判断该邮箱是否被人注册过,到userservice写mail_exist方法,还有接口别忘了。这个接口不需要洞,只需要完成userservice写mail_exist与接口即可 + /// + /// + /// + [HttpPost]//邮箱验证 + public async Task Email(string emailAddress) + { + emailAddress = emailAddress.Trim().ToLower(); + //先判断邮箱是否被注册使用过,如果被使用过,便不让操作 + if (!await _userService.mail_exist(emailAddress)) + { + string code = RandomHelper.GenerateRandomLetter(6); + code = code.ToUpper();//全部转为大写 + EmailHelper.sendMail(code, emailAddress); + + //我要把邮箱和对应的code加进到数据库,还有申请时间 + //设置10分钟过期 + //set不存在便添加,如果存在便替换 + //CacheHelper.SetCache(emailAddress, code, TimeSpan.FromSeconds(10)); + + return Result.Success("发送邮件成功,请查看邮箱(可能在垃圾箱)"); + } + else + { + return Result.Error("该邮箱已被注册"); + } + // 邮箱和验证码都要被记住,然后注册时候比对邮箱和验证码是不是都和现在生成的一样 + } + } +} \ No newline at end of file diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/UserController.cs b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/UserController.cs index 1dfd90a3..fd7ce24b 100644 --- a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/UserController.cs +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/UserController.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using Yi.Framework.Common.Models; using Yi.Framework.Interface; using Yi.Framework.Model.Models; +using Yi.Framework.WebCore; namespace Yi.Framework.ApiMicroservice.Controllers { @@ -69,5 +70,15 @@ namespace Yi.Framework.ApiMicroservice.Controllers await _userService.AddAsync(_user); return Result.Success(); } + + /// + /// 通过上下文对象获取user(注意,_user下只有userId),返回值为该用户下所有的menu,(注意子类递归)并且需要关联mould + /// + /// + [HttpPost] + public async Task GetMenuMould() + { + var _user= this.HttpContext.GetCurrentUserInfo(); + } } } diff --git a/Yi.Framework/Yi.Framework.Common/Helper/EmailHelper.cs b/Yi.Framework/Yi.Framework.Common/Helper/EmailHelper.cs new file mode 100644 index 00000000..fc797fb2 --- /dev/null +++ b/Yi.Framework/Yi.Framework.Common/Helper/EmailHelper.cs @@ -0,0 +1,125 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Net.Mail; +using System.Net.Sockets; +using System.Text; + +namespace Yi.Framework.Common +{ + public class EmailHelper + { + public static string fromMail { get; set; } + public static string pwdMail { get; set; } + public static string senderMail { get; set; } + public static string subjectMail { get; set; } + public static void Init(string fromMail,string pwdMail,string senderMail, string subjectMail) + { + EmailHelper.fromMail = fromMail; + EmailHelper.pwdMail = pwdMail; + EmailHelper.senderMail = senderMail; + EmailHelper.subjectMail = subjectMail; + } + + public static bool sendMail(string body, string toMail) + { + try + { + + //string fromMail = "454313500@qq.com"; + //string pwdMail = "yvjioburildgbhdf"; + MailMessage message = new MailMessage(); + //设置发件人,发件人需要与设置的邮件发送服务器的邮箱一致 + System.Net.Mail.MailAddress fromAddr = new System.Net.Mail.MailAddress(fromMail, EmailHelper.senderMail); + message.From = fromAddr; + + //设置收件人,可添加多个,添加方法与下面的一样 + message.To.Add(toMail); + + + //设置邮件标题 + message.Subject = EmailHelper.subjectMail; + + //设置邮件内容 + message.Body = body; + + //设置邮件发送服务器,服务器根据你使用的邮箱而不同,可以到相应的 邮箱管理后台查看,下面是QQ的 + System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("smtp.qq.com", 25) + ; + //设置发送人的邮箱账号和密码,POP3/SMTP服务要开启, 密码要是POP3/SMTP等服务的授权码 + client.Credentials = new System.Net.NetworkCredential(fromMail, pwdMail);//vtirsfsthwuadjfe fhszmpegwoqnecja + + //启用ssl,也就是安全发送 + client.EnableSsl = true; + + //发送邮件 + client.Send(message); + + return true; + } + catch + { + return false; + } + + } + + public static void 接受邮件() + { + using (TcpClient client = new TcpClient("pop.qq.com", 110)) + using (NetworkStream n = client.GetStream()) + { + GetEmail.ReadLine(n); // Read the welcome message. + GetEmail.SendCommand(n, "USER 1040079213@qq.com"); + GetEmail.SendCommand(n, "PASS odfaizoqdiupbfgi"); + GetEmail.SendCommand(n, "LIST"); // Retrieve message IDs + List messageIDs = new List(); + while (true) + { + string line = GetEmail.ReadLine(n); // e.g., "11876" + if (line == ".") break; + messageIDs.Add(int.Parse(line.Split(' ')[0])); // Message ID + } + foreach (int id in messageIDs) // Retrieve each message. + { + GetEmail.SendCommand(n, "RETR " + id); + string randomFile = Guid.NewGuid().ToString() + ".eml"; + using (StreamWriter writer = File.CreateText(randomFile)) + while (true) + { + string line = GetEmail.ReadLine(n); // Read next line of message. + if (line == ".") break; // Single dot = end of message. + if (line == "..") line = "."; // "Escape out" double dot. + writer.WriteLine(line); // Write to output file. + } + GetEmail.SendCommand(n, "DELE " + id); // Delete message off server. + } + GetEmail.SendCommand(n, "QUIT"); + } + } + } + //接受邮件pop + public class GetEmail + { + public static void SendCommand(Stream stream, string line) + { + byte[] data = Encoding.UTF8.GetBytes(line + "\r\n"); + stream.Write(data, 0, data.Length); + string response = ReadLine(stream); + if (!response.StartsWith("+OK")) + throw new Exception("POP Error: " + response); + } + public static string ReadLine(Stream s) + { + List lineBuffer = new List(); + while (true) + { + int b = s.ReadByte(); + if (b == 10 || b < 0) break; + if (b != 13) lineBuffer.Add((byte)b); + } + return Encoding.UTF8.GetString(lineBuffer.ToArray()); + } + } +} + diff --git a/Yi.Framework/Yi.Framework.Common/Helper/RandomHelper.cs b/Yi.Framework/Yi.Framework.Common/Helper/RandomHelper.cs new file mode 100644 index 00000000..9c9b61dd --- /dev/null +++ b/Yi.Framework/Yi.Framework.Common/Helper/RandomHelper.cs @@ -0,0 +1,99 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Text.RegularExpressions; + +namespace Yi.Framework.Common +{ + public class RandomHelper + { + public static string replaceBianLiang(string content) + { + content = content.Replace("{当前时间}", DateTime.Now.TimeOfDay.ToString()); + string[] bianliang = new string[] { "{随机字母}", "{随机数字}", "{随机汉字}" }; + Regex r; + int count; + string readstr = ""; + foreach (string str in bianliang) + { + count = (content.Length - content.Replace(str, "").Length) / str.Length; + if (str == "{随机汉字}") readstr = RandChina(count); + if (str == "{随机数字}") readstr = GenerateCheckCodeNum(count); + if (str == "{随机字母}") readstr = GenerateRandomLetter(count); + if (count > readstr.Length) count = readstr.Length; + r = new Regex(str.Replace("{", "\\{").Replace("}", "\\}")); + for (int i = 0; i < count; i++) + { + content = r.Replace(content, readstr.Substring(i, 1), 1); + } + } + return content; + } + + + /// + /// 随机生成字母 + /// + /// + /// + public static string GenerateRandomLetter(int Length) + { + char[] Pattern = new char[] { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' }; + string result = ""; + int n = Pattern.Length; + Random random = new Random(~unchecked((int)DateTime.Now.Ticks)); + for (int i = 0; i < Length; i++) + { + int rnd = random.Next(0, n); + result += Pattern[rnd]; + } + return result; + } + + /// + /// 随机生成数字 + /// + /// + /// + public static string GenerateCheckCodeNum(int codeCount) + { + int rep = 0; + string str = string.Empty; + long num2 = DateTime.Now.Ticks + rep; + rep++; + Random random = new Random(((int)(((ulong)num2) & 0xffffffffL)) | ((int)(num2 >> rep))); + for (int i = 0; i < codeCount; i++) + { + int num = random.Next(); + str = str + ((char)(0x30 + ((ushort)(num % 10)))).ToString(); + } + return str; + } + + /// + /// 此函数为生成指定数目的汉字 + /// + /// 汉字数目 + /// 所有汉字 + public static string RandChina(int charLen) + { + int area, code;//汉字由区位和码位组成(都为0-94,其中区位16-55为一级汉字区,56-87为二级汉字区,1-9为特殊字符区) + StringBuilder strtem = new StringBuilder(); + Random rand = new Random(); + for (int i = 0; i < charLen; i++) + { + area = rand.Next(16, 88); + if (area == 55)//第55区只有89个字符 + { + code = rand.Next(1, 90); + } + else + { + code = rand.Next(1, 94); + } + strtem.Append(Encoding.GetEncoding("GB2312").GetString(new byte[] { Convert.ToByte(area + 160), Convert.ToByte(code + 160) })); + } + return strtem.ToString(); + } + } +} diff --git a/Yi.Vue/package-lock.json b/Yi.Vue/package-lock.json index 49231f16..894a1b6e 100644 --- a/Yi.Vue/package-lock.json +++ b/Yi.Vue/package-lock.json @@ -9026,6 +9026,11 @@ "resolved": "https://registry.npmmirror.com/vuetify/download/vuetify-2.5.9.tgz", "integrity": "sha1-tubZ//ShaRhY80FezrKnXKcG0hE=" }, + "vuetify-dialog": { + "version": "2.0.17", + "resolved": "https://registry.nlark.com/vuetify-dialog/download/vuetify-dialog-2.0.17.tgz", + "integrity": "sha1-vhmMGHkymnPXiRcIDqWX0BaSdz0=" + }, "vuetify-loader": { "version": "1.7.3", "resolved": "https://registry.nlark.com/vuetify-loader/download/vuetify-loader-1.7.3.tgz?cache=0&sync_timestamp=1631946975383&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fvuetify-loader%2Fdownload%2Fvuetify-loader-1.7.3.tgz", @@ -9080,6 +9085,11 @@ } } }, + "vuex": { + "version": "3.6.2", + "resolved": "https://registry.nlark.com/vuex/download/vuex-3.6.2.tgz", + "integrity": "sha1-I2vAhqhww655lG8QfxbeWdWJXnE=" + }, "watchpack": { "version": "1.7.5", "resolved": "https://registry.nlark.com/watchpack/download/watchpack-1.7.5.tgz", diff --git a/Yi.Vue/package.json b/Yi.Vue/package.json index a5c5c396..0e1983c0 100644 --- a/Yi.Vue/package.json +++ b/Yi.Vue/package.json @@ -11,7 +11,9 @@ "vue": "^2.6.11", "vue-chartist": "^2.3.1", "vue-router": "^3.2.0", - "vuetify": "^2.4.0" + "vuetify": "^2.4.0", + "vuetify-dialog": "^2.0.17", + "vuex": "^3.6.2" }, "devDependencies": { "@vue/cli-plugin-router": "~4.5.0", diff --git a/Yi.Vue/src/api/accountApi.js b/Yi.Vue/src/api/accountApi.js new file mode 100644 index 00000000..7c33252c --- /dev/null +++ b/Yi.Vue/src/api/accountApi.js @@ -0,0 +1,39 @@ +import myaxios from '@/util/myaxios' +export default { + login(username, password) { + return myaxios({ + url: '/Account/login', + method: 'post', + data: { + username, + password + } + }) + }, + logout() { + return myaxios({ + url: '/Account/logout', + method: 'post', + }) + }, + logged() { + return myaxios({ + url: '/Account/logged', + method: 'post', + }) + }, + register(username, password, email, code) { + return myaxios({ + url: `/Account/register?code=${code}`, + method: 'post', + data: { username, password, email } + }) + }, + email(emailAddress) { + return myaxios({ + url: `/Account/email?emailAddress=${emailAddress}`, + method: 'post', + }) + } + +} \ No newline at end of file diff --git a/Yi.Vue/src/api/actionApi.js b/Yi.Vue/src/api/actionApi.js new file mode 100644 index 00000000..902f625f --- /dev/null +++ b/Yi.Vue/src/api/actionApi.js @@ -0,0 +1,30 @@ +import myaxios from '@/util/myaxios' +export default { + getActions() { + return myaxios({ + url: '/Action/getActions', + method: 'get' + }) + }, + addAction(action) { + return myaxios({ + url: '/action/addAction', + method: 'post', + data: action + }) + }, + updateAction(action) { + return myaxios({ + url: '/action/UpdateAction', + method: 'post', + data: action + }) + }, + delActionList(Ids) { + return myaxios({ + url: '/action/DelAllAction', + method: 'post', + data: Ids + }) + }, +} \ No newline at end of file diff --git a/Yi.Vue/src/api/fileApi.js b/Yi.Vue/src/api/fileApi.js new file mode 100644 index 00000000..4162c042 --- /dev/null +++ b/Yi.Vue/src/api/fileApi.js @@ -0,0 +1,16 @@ +import myaxios from '@/util/myaxios' +export default { + OnPostUploadImage(file) { + return myaxios({ + url: '/File/OnPostUploadImage', + method: 'post', + data: file + }) + }, + getLogs() { + return myaxios({ + url: '/File/GetLogs', + method: 'get' + }) + } +} \ No newline at end of file diff --git a/Yi.Vue/src/api/roleApi.js b/Yi.Vue/src/api/roleApi.js new file mode 100644 index 00000000..b539ee43 --- /dev/null +++ b/Yi.Vue/src/api/roleApi.js @@ -0,0 +1,50 @@ +import myaxios from '@/util/myaxios' +export default { + getRoles() { + return myaxios({ + url: '/Role/getRoles', + method: 'get' + }) + }, + AddRole(role) { + return myaxios({ + url: '/Role/AddRole', + method: 'post', + data: role + }) + }, + delRole(roleId) { + return myaxios({ + url: `/Role/DelRole?roleId=${roleId}`, + method: 'get' + }) + }, + updateRole(role) { + return myaxios({ + url: '/role/updateRole', + method: 'post', + data: role + }) + }, + delRoleList(Ids) { + return myaxios({ + url: '/role/delAllRole', + method: 'post', + data: Ids + }) + }, + setAction(Id, Ids) { + return myaxios({ + url: '/role/setAction', + method: 'post', + data: { "Id": Id, "Ids": Ids } + }) + }, + GetActionByRoleId(roleId) { + return myaxios({ + url: `/role/GetActionByRoleId?roleId=${roleId}`, + method: 'get' + }) + } + +} \ No newline at end of file diff --git a/Yi.Vue/src/api/userApi.js b/Yi.Vue/src/api/userApi.js new file mode 100644 index 00000000..99329ebe --- /dev/null +++ b/Yi.Vue/src/api/userApi.js @@ -0,0 +1,101 @@ +import myaxios from '@/util/myaxios' +export default { + getAllUser() { + return myaxios({ + url: '/User/getAllUser', + method: 'get' + }) + }, + getUserByUserId(userId) { + if (userId == undefined) { + userId = 0; + } + return myaxios({ + url: `/User/getUserByUserId?userId=${userId}`, + method: 'get' + }) + }, + + addUser(user) { + return myaxios({ + url: '/User/addUser', + method: 'post', + data: user + }) + }, + delUser(userId) { + return myaxios({ + url: `/User/delUser?userId=${userId}`, + method: 'get' + }) + }, + updateUser(user) { + return myaxios({ + url: '/User/updateUser', + method: 'post', + data: user + }) + }, + tryUpdateUser(form) { + return myaxios({ + url: '/User/tryUpdateUser', + method: 'post', + data: form + }) + }, + + delUserList(Ids) { + return myaxios({ + url: '/User/delAllUser', + method: 'post', + data: Ids + }) + }, + setRole(Id, Ids) { + return myaxios({ + url: '/User/setRole', + method: 'post', + data: { "Id": Id, "Ids": Ids } + }) + }, + + setRoleList(userIds, roleIds) { + return myaxios({ + url: '/User/setRoleList', + method: 'post', + data: { "userIds": userIds, "roleIds": roleIds } + }) + }, + getRoleByuserId(userId) { + if (userId == undefined) { + userId = 0; + } + return myaxios({ + url: `/User/getRoleByuserId?userId=${userId}`, + method: 'get' + }) + }, + getSpecialAction(userId) { + return myaxios({ + url: `/User/getSpecialAction?userId=${userId}`, + method: 'get' + }) + }, + setSpecialAction(Id, Ids) { + return myaxios({ + url: '/User/setSpecialAction', + method: 'post', + data: { "Id": Id, "Ids": Ids } + }) + }, + getActionByUserId(userId) { + if (userId == undefined) { + userId = 0; + } + return myaxios({ + url: `/User/getActionByUserId?userId=${userId}`, + method: 'get' + }) + } + +} \ No newline at end of file diff --git a/Yi.Vue/src/assets/login.svg b/Yi.Vue/src/assets/login.svg new file mode 100644 index 00000000..e27fd805 --- /dev/null +++ b/Yi.Vue/src/assets/login.svg @@ -0,0 +1 @@ +instat_analysis \ No newline at end of file diff --git a/Yi.Vue/src/layouts/login/LayoutLogin.vue b/Yi.Vue/src/layouts/login/LayoutLogin.vue new file mode 100644 index 00000000..9af7f789 --- /dev/null +++ b/Yi.Vue/src/layouts/login/LayoutLogin.vue @@ -0,0 +1,65 @@ + + diff --git a/Yi.Vue/src/main.js b/Yi.Vue/src/main.js index 7d3cd181..06603134 100644 --- a/Yi.Vue/src/main.js +++ b/Yi.Vue/src/main.js @@ -3,6 +3,8 @@ import App from './App.vue' import router from './router' import vuetify from './plugins/vuetify' import './plugins' +import './store/index' + Vue.config.productionTip = false new Vue({ diff --git a/Yi.Vue/src/router/index.js b/Yi.Vue/src/router/index.js index d62280bd..2c24a88b 100644 --- a/Yi.Vue/src/router/index.js +++ b/Yi.Vue/src/router/index.js @@ -1,5 +1,9 @@ import Vue from 'vue' import VueRouter from 'vue-router' + +import LayoutLogin from '../layouts/login/LayoutLogin.vue' +import login from '../views/login.vue' +import register from '../views/register.vue' import { trailingSlash } from '@/util/helpers' import { layout, @@ -18,11 +22,29 @@ const router = new VueRouter({ return { x: 0, y: 0 } }, - routes: [layout('Default', [ - route('Index'), - route('AdmUser', null, 'AdmUser'), - route('AdmRole', null, 'AdmRole'), - ])] + routes: [{ + path: '/layoutLogin', + name: 'layoutLogin', + component: LayoutLogin, + redirect: "/login", + children: [{ + path: "/login", + name: "login", + component: login + }, + { + path: '/register', + name: 'register', + component: register + } + ] + }, + layout('Default', [ + route('Index'), + route('AdmUser', null, 'AdmUser'), + route('AdmRole', null, 'AdmRole'), + ]) + ] }) router.beforeEach((to, from, next) => { return to.path.endsWith('/') ? next() : next(trailingSlash(to.path)) diff --git a/Yi.Vue/src/store/index.js b/Yi.Vue/src/store/index.js new file mode 100644 index 00000000..ea139770 --- /dev/null +++ b/Yi.Vue/src/store/index.js @@ -0,0 +1,18 @@ +import Vue from 'vue' +import Vuex from 'vuex' +import home from './modules/home' +import user from './modules/user' +import theme from './modules/theme' +import loader from './modules/loader' +Vue.use(Vuex); + +//实例化 +const store = new Vuex.Store({ + modules: { + home, + user, + theme, + loader + } +}) +export default store \ No newline at end of file diff --git a/Yi.Vue/src/store/modules/home.js b/Yi.Vue/src/store/modules/home.js new file mode 100644 index 00000000..46b3efd0 --- /dev/null +++ b/Yi.Vue/src/store/modules/home.js @@ -0,0 +1,42 @@ +const state = { //状态 + plateId: 0, + discussId: 0, + plateString: "", +} + +const mutations = { //变化//载荷 + SET_PLATEID(state, n) { + state.plateId = n + }, + SET_DOSCUSSIDSTRING(state, n) { + state.plateString = n + }, + SET_DOSCUSSID(state, n) { + state.discussId = n + }, +} + +//在action中可以配合axios进行权限判断 +const actions = { //动作 + set_plateId(context, n) { + context.commit('SET_PLATEID', n) + }, + set_plateString(context, n) { + context.commit('SET_DOSCUSSIDSTRING', n) + }, + set_discussId(context, n) { + context.commit('SET_DOSCUSSID', n) + } +} + +// const getters = { //类似与计算属性 派生属性 +// msg(state) { +// if (state.count > 80) { +// return "成绩优异" +// } else { +// return "成绩不合格" +// } +// } +// } + +export default { state, mutations, actions } \ No newline at end of file diff --git a/Yi.Vue/src/store/modules/loader.js b/Yi.Vue/src/store/modules/loader.js new file mode 100644 index 00000000..64b0b327 --- /dev/null +++ b/Yi.Vue/src/store/modules/loader.js @@ -0,0 +1,34 @@ +const state = { //状态 + load: false +} + +const mutations = { //变化//载荷 + OPEN(state) { + state.load = true; + }, + CLOSE(state) { + state.load = false; + }, +} + +//在action中可以配合axios进行权限判断 +const actions = { //动作 + openLoad(context) { + context.commit('OPEN') + }, + closeLoad(context) { + context.commit('CLOSE') + } +} + +// const getters = { //类似与计算属性 派生属性 +// msg(state) { +// if (state.count > 80) { +// return "成绩优异" +// } else { +// return "成绩不合格" +// } +// } +// } + +export default { state, mutations, actions } \ No newline at end of file diff --git a/Yi.Vue/src/store/modules/theme.js b/Yi.Vue/src/store/modules/theme.js new file mode 100644 index 00000000..131d8683 --- /dev/null +++ b/Yi.Vue/src/store/modules/theme.js @@ -0,0 +1,33 @@ +import vuetify from '../../plugins/vuetify'; +const state = { //状态 + light: { + primary: '#1976D2', + secondary: '#424242', + accent: '#82B1FF', + error: '#FF5252', + info: '#2196F3', + success: '#4CAF50', + warning: '#FFC107', + cyan: "#FAB2B1", + blue: "#2196F3" + }, + dark: {} +} + +const mutations = { //变化//载荷 + SET_Light(state, n) { + state.light = n + vuetify.framework.theme.themes.light = n + }, +} + +//在action中可以配合axios进行权限判断 +const actions = { //动作 + set_light(context, n) { + context.commit('SET_Light', n) + }, + +} + + +export default { state, mutations, actions } \ No newline at end of file diff --git a/Yi.Vue/src/store/modules/user.js b/Yi.Vue/src/store/modules/user.js new file mode 100644 index 00000000..0b81c521 --- /dev/null +++ b/Yi.Vue/src/store/modules/user.js @@ -0,0 +1,122 @@ +import { getToken, setToken, getUser, setUser, removeToken } from '../../util/usertoken' +import accountApi from "@/api/accountApi" + +//再导入axion请求 +const state = { //状态 + token: getToken(), + user: getUser() +} + +const mutations = { //变化//载荷 + SET_TOKEN(state, token) { + state.token = token + setToken(token) + }, + SET_USER(state, user) { + state.user = user + setUser(user) + } +} + + + +//在action中可以配合axios进行权限判断 +const actions = { //动作 + setIcon({ commit, state }, icon) { + state.user.icon = icon + commit('SET_USER', state.user) + }, + + + setLevel({ commit, state }, level) { + + commit('SET_USER', state.user) + }, + + // qqUpdate({ state }, openid) { + // return new Promise((resolv, reject) => { + // qqApi.qqupdate(openid, state.user.id).then(resp => { + // resolv(resp) + // }).catch(error => { + // reject(error) + // }) + // }) + // }, + + // qqLogin({ commit }, openid) { + // return new Promise((resolv, reject) => { + // qqApi.qqlogin(openid).then(resp => { + // if (resp.status) { + // commit('SET_TOKEN', resp.data.token) + // commit('SET_USER', resp.data.user) + // } + // resolv(resp) + // }).catch(error => { + // reject(error) + // }) + // }) + // }, + + Login({ commit }, form) { + return new Promise((resolv, reject) => { + accountApi.login(form.username.trim(), form.password.trim()).then(resp => { + if (resp.status) { + commit('SET_TOKEN', resp.data.token) + commit('SET_USER', resp.data.user) + } + + resolv(resp) + }).catch(error => { + reject(error) + }) + }) + }, + + + + Register({ commit }, form) { + return new Promise((resolv, reject) => { + accountApi.register(form.username.trim(), form.password.trim(), form.email.trim(), form.code.trim()).then(resp => { + resolv(resp) + }).catch(error => { + reject(error) + }) + }) + }, + Logged({ commit }) { + return new Promise((resolv, reject) => { + accountApi.logged().then(resp => { + resolv(resp) + }).catch(error => { + reject(error) + }) + }) + }, + + // GetUserInfo({ commit, state }) { + // return new Promise((resolv, reject) => { + // // getUserInfo(state.token).then(response => { + // // commit('SET_USER', response.data) + // // resolve(response) + // // }).catch(error=>{ + // // reject(error) + // // }) + // }) + // }, + Logout({ commit, state }) { + return new Promise((resolv, reject) => { + accountApi.logout().then(response => { + commit('SET_TOKEN', '') + commit('SET_USER', null) + removeToken() + resolv(response) + }).catch(error => { + reject(error) + }) + }) + } + +} + + +export default { state, mutations, actions } \ No newline at end of file diff --git a/Yi.Vue/src/views/login.vue b/Yi.Vue/src/views/login.vue new file mode 100644 index 00000000..e71e1386 --- /dev/null +++ b/Yi.Vue/src/views/login.vue @@ -0,0 +1,163 @@ + + diff --git a/Yi.Vue/src/views/register.vue b/Yi.Vue/src/views/register.vue new file mode 100644 index 00000000..8164c733 --- /dev/null +++ b/Yi.Vue/src/views/register.vue @@ -0,0 +1,238 @@ + +