Skip to content

Commit

Permalink
栏目添加类型,后台添加网站用户列表
Browse files Browse the repository at this point in the history
  • Loading branch information
yinMrsir committed Apr 21, 2023
1 parent 021effa commit 801f768
Show file tree
Hide file tree
Showing 13 changed files with 135 additions and 19 deletions.
8 changes: 4 additions & 4 deletions Nest-server/src/modules/basic/banner/banner.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { CreateBannerDto } from './dto/create-banner.dto';
import { UpdateBannerDto } from './dto/update-banner.dto';
import {Banner} from "./entities/banner.entity";
import { Banner } from './entities/banner.entity';

@Injectable()
export class BannerService {
constructor(
@InjectRepository(Banner)
private readonly bannerRepository: Repository<Banner>
private readonly bannerRepository: Repository<Banner>,
) {}

create(createBannerDto: CreateBannerDto) {
Expand All @@ -20,8 +20,8 @@ export class BannerService {
const [rows, total] = await this.bannerRepository.findAndCount();
return {
rows,
total
}
total,
};
}

update(updateBannerDto: UpdateBannerDto) {
Expand Down
2 changes: 1 addition & 1 deletion Nest-server/src/modules/column/column.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { User, UserEnum } from '../../common/decorators/user.decorator';
import { UserInfoPipe } from '../../common/pipes/user-info.pipe';
import { DataObj } from '../../common/class/data-obj.class';
import { Public } from '../../common/decorators/public.decorator';
import {ApiException} from "../../common/exceptions/api.exception";
import { ApiException } from '../../common/exceptions/api.exception';

@Controller('column')
export class ColumnController {
Expand Down
4 changes: 4 additions & 0 deletions Nest-server/src/modules/column/entities/column.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export class Columns extends BaseEntity {
@IsString()
name: string;

@Column('varchar', { length: 1, comment: '栏目类型', default: '1' })
@IsString()
type: string;

@Column('varchar', { length: 50, comment: '目录名' })
@IsString()
value: string;
Expand Down
9 changes: 8 additions & 1 deletion Nest-server/src/modules/monitor/cache/cache.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
SYSCONFIG_KEY,
WEB_INDEX,
WEB_TYPE,
WEB_USER_KEY,
} from 'src/common/contants/redis.contant';
import { CacheService } from './cache.service';
import { DataObj } from '../../../common/class/data-obj.class';
Expand All @@ -26,7 +27,7 @@ export class CacheController {
cacheName: USER_TOKEN_KEY,
cacheKey: '',
cacheValue: '',
remark: '用户信息',
remark: '系统用户',
});
this.caches.push({
cacheName: SYSCONFIG_KEY,
Expand All @@ -52,6 +53,12 @@ export class CacheController {
cacheValue: '',
remark: '栏目数据',
});
this.caches.push({
cacheName: WEB_USER_KEY,
cacheKey: '',
cacheValue: '',
remark: '网站用户',
});
}

@Get('getNames')
Expand Down
3 changes: 3 additions & 0 deletions Nest-server/src/modules/web/user/dto/req-web-user.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { WebUser } from '../entities/web-user.entity';
import { PaginationDto } from '../../../../common/dto/pagination.dto';

export class RegWebUserDto extends WebUser {}

Expand All @@ -7,3 +8,5 @@ export class LoginWebUserDto {

password: string;
}

export class QueryWebUserDto extends PaginationDto {}
25 changes: 23 additions & 2 deletions Nest-server/src/modules/web/user/web-user.controller.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
import { Body, Controller, Get, Post, Req, UseGuards } from '@nestjs/common';
import {
Body,
Controller,
Get,
Post,
Query,
Req,
UseGuards,
} from '@nestjs/common';
import { WebUserService } from './web-user.service';
import { Request } from 'express';
import { Public } from '../../../common/decorators/public.decorator';
import { LoginWebUserDto, RegWebUserDto } from './dto/req-web-user.dto';
import {
LoginWebUserDto,
QueryWebUserDto,
RegWebUserDto,
} from './dto/req-web-user.dto';
import { LocalWebAuthGuard } from 'src/common/guards/local-web-auth.guard';
import { JwtWebAuthGuard } from '../../../common/guards/jwt-web-auth.guard';
import { DataObj } from '../../../common/class/data-obj.class';
import { User, UserEnum } from '../../../common/decorators/user.decorator';
import { PaginationPipe } from '../../../common/pipes/pagination.pipe';

@Controller('web/user')
export class WebUserController {
Expand All @@ -32,4 +45,12 @@ export class WebUserController {
const data = await this.webUserService.info(userId);
return new DataObj(data);
}

@Get('list')
async list(@Query(PaginationPipe) queryWebUserDto: QueryWebUserDto) {
const [rows, total] = await this.webUserService.findListPage(
queryWebUserDto,
);
return { rows, total };
}
}
28 changes: 27 additions & 1 deletion Nest-server/src/modules/web/user/web-user.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@nestjs/common';
import { RegWebUserDto } from './dto/req-web-user.dto';
import { QueryWebUserDto, RegWebUserDto } from './dto/req-web-user.dto';
import { SharedService } from '../../../shared/shared.service';
import { WebUser } from './entities/web-user.entity';
import { Repository } from 'typeorm';
Expand All @@ -8,6 +8,7 @@ import { Request } from 'express';
import { JwtService } from '@nestjs/jwt';
import { WEB_USER_KEY } from '../../../common/contants/redis.contant';
import { InjectRedis, Redis } from '@nestjs-modules/ioredis';
import * as moment from 'moment';

@Injectable()
export class WebUserService {
Expand Down Expand Up @@ -48,6 +49,16 @@ export class WebUserService {
'EX',
60 * 60 * 24,
);
// 保存最后登录时间和最后登录IP
await this.webUserRepository.update(
{
userId: user.userId,
},
{
loginIp: this.sharedService.getReqIP(request),
loginDate: moment().format('YYYY-MM-DDTHH:mm:ss'),
},
);
return {
token: jwtSign,
};
Expand All @@ -56,4 +67,19 @@ export class WebUserService {
info(userId: number) {
return this.webUserRepository.findOneBy({ userId });
}

findListPage(queryWebUserDto: QueryWebUserDto) {
return this.webUserRepository.findAndCount({
take: queryWebUserDto.take,
skip: queryWebUserDto.skip,
select: [
'email',
'status',
'createTime',
'userId',
'loginDate',
'loginIp',
],
});
}
}
3 changes: 2 additions & 1 deletion Nuxt-web/layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
<ul>
<li :class="route.path === '/' ? 'active' : ''"><NuxtLink to="/">首页</NuxtLink></li>
<li v-for="item in navigation" :class="route.params.column === item.value ? 'active' : ''">
<nuxt-link :to="`/${item.value}`">{{item.name}}</nuxt-link >
<nuxt-link :to="`/${item.value}`" v-if="+item.type === 1">{{item.name}}</nuxt-link>
<nuxt-link :to="item.value" target="_blank" v-if="+item.type === 2">{{item.name}}</nuxt-link>
</li>
</ul>
</nav>
Expand Down
19 changes: 13 additions & 6 deletions Vue3-admin/src/components/TablePro/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</el-form>

<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-col :span="1.5" v-if="isShowButtonList">
<el-button
v-if="formOptions.length > 0"
type="primary"
Expand All @@ -37,7 +37,7 @@
@click="handleAdd"
>新增</el-button>
</el-col>
<el-col :span="1.5">
<el-col :span="1.5" v-if="isShowButtonList">
<el-button
type="success"
plain
Expand All @@ -46,7 +46,7 @@
@click="handleUpdate"
>修改</el-button>
</el-col>
<el-col :span="1.5">
<el-col :span="1.5" v-if="isShowButtonList">
<el-button
type="danger"
plain
Expand All @@ -60,7 +60,7 @@

<el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column prop="id" width="60" label="ID" align="center" />
<el-table-column v-if="isShowIdColumn" prop="id" width="60" label="ID" align="center" />
<template v-for="item in TableOptions">
<template v-if="item.slot" v-bind="item">
<slot :name="item.slot"></slot>
Expand Down Expand Up @@ -144,7 +144,6 @@
append-to-body
:close-on-click-modal="false">
<el-form ref="formRef" :model="form" label-width="100px" :rules="rules">

<el-form-item :label="`${item.title}:`" :prop="item.field" v-for="item in formOptions">
<template v-if="item.formSlot">
<slot :name="item.formSlot" v-bind="item"></slot>
Expand All @@ -158,7 +157,7 @@
/>
</template>
<template v-else-if="item.type === 'radio'">
<el-radio-group v-model="form[item.field]">
<el-radio-group v-model="form[item.field]" v-bind="item.formProps" @change="item.change">
<el-radio :label="radio.value" v-for="(radio, index) in item.options" :key="index">{{ radio.label }}</el-radio>
</el-radio-group>
</template>
Expand Down Expand Up @@ -279,6 +278,14 @@ const props = defineProps({
formDialogWidth: {
type: String,
default: '600px'
},
isShowIdColumn: {
type: Boolean,
default: true
},
isShowButtonList: {
type: Boolean,
default: true
}
})
const list = ref([])
Expand Down
16 changes: 14 additions & 2 deletions Vue3-admin/src/views/column/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,30 @@
:create-fn="createColumn"
:update-fn="updateColumn"
:delete-fn="deleteColumn"
:form-params="{ type: '1' }"
/>
</div>
</template>

<script setup>
import { getColumnList, createColumn, updateColumn, deleteColumn } from './services'
const { proxy } = getCurrentInstance();
const { sys_normal_disable } = proxy.useDict("sys_normal_disable");
const { sys_normal_disable, column_type } = proxy.useDict('sys_normal_disable', 'column_type');
const columns = ref([
{ title: '栏目名称', field: 'name', add: [{required: true, message: '请输入栏目名称'}] },
{ title: '目录名', field: 'value', add: [{required: true, message: '请输入目录名'}] },
{
title: '类型',
field: 'type',
type: 'radio',
options: column_type,
add: true
},
{
title: '目录/路径',
field: 'value',
add: [{required: true, message: '请输入目录/路径'}]
},
{ title: '排序', field: 'order', type: 'number', add: true },
{ title: '状态', field: 'status', add: true, type: 'radio', options: sys_normal_disable },
{ title: '备注', field: 'remark', add: true, formProps: { type: 'textarea' } },
Expand Down
2 changes: 1 addition & 1 deletion Vue3-admin/src/views/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
type="primary"
icon="Cloudy"
plain
@click="goTarget('https://gitee.com/yinMrsir/chunyu-cms')"
@click="goTarget('https://gitee.com/chunyu-cms/chunyu-cms')"
>访问码云</el-button
>
</p>
Expand Down
25 changes: 25 additions & 0 deletions Vue3-admin/src/views/webUser/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<template>
<div class="app-container">
<table-pro
:columns="columns"
:table-request-fn="getWebUserList"
:is-show-id-column="false"
:is-show-button-list="false"
></table-pro>
</div>
</template>

<script setup>
import { getWebUserList } from './services'
const { proxy } = getCurrentInstance()
const { sys_normal_disable } = proxy.useDict("sys_normal_disable");
const columns = ref([
{ title: '用户ID', field: 'userId' },
{ title: '账号', field: 'email' },
{ title: '状态', field: 'status', type: 'select', options: sys_normal_disable, add: true },
{ title: '注册时间', field: 'createTime', type: 'dateTime' },
{ title: '最后登录IP', field: 'loginIp' },
{ title: '最后登录时间', field: 'loginDate', type: 'dateTime' },
])
</script>
10 changes: 10 additions & 0 deletions Vue3-admin/src/views/webUser/services.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import request from '@/utils/request'

// 查询网站用户
export function getWebUserList(query) {
return request({
url: '/web/user/list',
method: 'get',
params: query
})
}

0 comments on commit 801f768

Please sign in to comment.