mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/fe-student.git
synced 2025-12-11 20:06:49 +08:00
接口初始化 第一版
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||||
*/
|
*/
|
||||||
export const BASE = 'http://111.231.196.214:30001/manageApi'
|
export const BASE = 'http://111.231.196.214:30001/manageApi'
|
||||||
|
export const LOGIN = '/admin/CheckUser/userLogin post'
|
||||||
// export const FILE_UPLOAD = 'http://111.231.196.214:30001/file/upload'
|
// export const FILE_UPLOAD = 'http://111.231.196.214:30001/file/upload'
|
||||||
export const FILE_UPLOAD = '/file/upload'
|
export const FILE_UPLOAD = '/file/upload'
|
||||||
export const COMMON_TOKEN = 'https://upload-z2.qiniup.com'
|
export const COMMON_TOKEN = 'https://upload-z2.qiniup.com'
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ export function useRequest(_url, params = {}) {
|
|||||||
export async function request(_url, params) {
|
export async function request(_url, params) {
|
||||||
const s = _url.split(' ')
|
const s = _url.split(' ')
|
||||||
let url = s[0]
|
let url = s[0]
|
||||||
const method = s[1] || 'get'
|
const method = s[1]?.toLowerCase() || 'get'
|
||||||
if (method === 'get') {
|
if (method === 'get') {
|
||||||
let paramsArray = [];
|
let paramsArray = [];
|
||||||
//拼接参数
|
//拼接参数
|
||||||
@@ -55,16 +55,17 @@ export async function request(_url, params) {
|
|||||||
...method !== 'get' ? {data: JSON.stringify(body)} : {}
|
...method !== 'get' ? {data: JSON.stringify(body)} : {}
|
||||||
}).then(resp => resp.data).then(response => {
|
}).then(resp => resp.data).then(response => {
|
||||||
if (response.code !== 200 && response.code !== 0) {
|
if (response.code !== 200 && response.code !== 0) {
|
||||||
if (response.code === 3 || response.code === 4 || response.code === 100) {
|
console.log(1111111111)
|
||||||
// router.push({path: '/login'})
|
console.log(response.code)
|
||||||
return
|
if (import.meta.env.DEV && response.code === 1000) {
|
||||||
|
router.push({path: '/login'})
|
||||||
} else {
|
} else {
|
||||||
// response.showMsg && notification.open({
|
// response.showMsg && notification.open({
|
||||||
// message: response.showMsg,
|
// message: response.showMsg,
|
||||||
// duration: 2,
|
// duration: 2,
|
||||||
// });
|
// });
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
throw new Error('接口异常')
|
||||||
}
|
}
|
||||||
return response
|
return response
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
|
|||||||
@@ -1,3 +1,13 @@
|
|||||||
export function useImage(src) {
|
export function useImage(src) {
|
||||||
return new URL(`../assets/image/${src}`, import.meta.url).href
|
return new URL(`../assets/image/${src}`, import.meta.url).href
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function setCookie(name, value, perpetual) {
|
||||||
|
const d = new Date()
|
||||||
|
d.setDate(perpetual * 24 * 60 * 60 * 1000)
|
||||||
|
document.cookie = `${name}=${value};expires=${d.toGMTString()};path=/`
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getCookie(name) {
|
||||||
|
return document.cookie?.split(";").find(e => e.includes(name)).replace(`${name}=`, '') || ''
|
||||||
|
}
|
||||||
@@ -63,18 +63,18 @@
|
|||||||
{{ d.discussExplain }}
|
{{ d.discussExplain }}
|
||||||
</div>
|
</div>
|
||||||
<div class="allstar clearfix">
|
<div class="allstar clearfix">
|
||||||
<div @click="comment(i)" style="display: flex;cursor: pointer">
|
<div @click="comment(d)" style="display: flex;cursor: pointer">
|
||||||
<span class="iconfont icon-pinglun" style="color:#b3bdc4"></span>
|
<span class="iconfont icon-pinglun" style="color:#b3bdc4"></span>
|
||||||
<div class="count"> {{ d.discussReviewCount }}</div>
|
<div class="count"> {{ d.commentNum || 0 }}</div>
|
||||||
</div>
|
</div>
|
||||||
<div @click="like(i)" style="display: flex;cursor: pointer">
|
<div @click="like(d)" style="display: flex;cursor: pointer">
|
||||||
<span class="iconfont icon-dianzan" :style="{color:d.isLike?'red':'#b3bdc4',marginLeft: '19px'}"></span>
|
<span class="iconfont icon-dianzan" :style="{color:d.praised?'red':'#b3bdc4',marginLeft: '19px'}"></span>
|
||||||
<div class="count"> {{ d.discussLikeCount }}</div>
|
<div class="count"> {{ d.praiseNum || 0 }}</div>
|
||||||
</div>
|
</div>
|
||||||
<div @click="collection(i)" style="display: flex;cursor: pointer">
|
<div @click="collection(d)" style="display: flex;cursor: pointer">
|
||||||
<span class="iconfont icon-shoucang"
|
<span class="iconfont icon-shoucang"
|
||||||
:style="{color:d.isCollection?'red':'#b3bdc4',marginLeft: '19px'}"></span>
|
:style="{color:d.collected?'red':'#b3bdc4',marginLeft: '19px'}"></span>
|
||||||
<div class="count"> {{ d.discussCollectionCount }}</div>
|
<div class="count"> {{ d.collectionNum || 0 }}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="thinline"></div>
|
<div class="thinline"></div>
|
||||||
@@ -87,7 +87,11 @@
|
|||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import {request, useRequest} from "@/api/request";
|
import {request, useRequest} from "@/api/request";
|
||||||
import {DISCUSS_COLLECTION, DISCUSS_DETAIL, DISCUSS_LIKE, DISCUSS_LIST, TASK_VOTE_DETAIL} from "@/api/api";
|
import {
|
||||||
|
COMMENT_COLLECTION,
|
||||||
|
COMMENT_PRAISE,
|
||||||
|
DISCUSS_LIST,
|
||||||
|
} from "@/api/api";
|
||||||
import {reactive, ref, toRefs} from "vue";
|
import {reactive, ref, toRefs} from "vue";
|
||||||
import {useRoute, useRouter} from "vue-router";
|
import {useRoute, useRouter} from "vue-router";
|
||||||
|
|
||||||
@@ -100,29 +104,24 @@ const param = ref({
|
|||||||
})
|
})
|
||||||
const {data: projectInfo} = useRequest(DISCUSS_LIST, param.value)
|
const {data: projectInfo} = useRequest(DISCUSS_LIST, param.value)
|
||||||
|
|
||||||
const {data: disDetail} = useRequest(DISCUSS_DETAIL, {id})
|
|
||||||
const state = reactive({
|
const state = reactive({
|
||||||
activeName: "first",
|
activeName: "first",
|
||||||
});
|
});
|
||||||
|
|
||||||
function comment(i) {
|
function comment({discussId: id}) {
|
||||||
const id = data.value.rows[i].discussId
|
|
||||||
router.push({path: 'discussdetail', query: {id}})
|
router.push({path: 'discussdetail', query: {id}})
|
||||||
}
|
}
|
||||||
|
|
||||||
//todo 帖子点赞收藏 是否已经点赞收藏
|
function like(d) {
|
||||||
function like(i) {
|
d.praised ? (d.praiseNum -= 1) : (d.praiseNum += 1)
|
||||||
data.value.rows[i].isLike ? (data.value.rows[i].discussLikeCount -= 1) : (data.value.rows[i].discussLikeCount += 1)
|
d.praised = !d.praised
|
||||||
data.value.rows[i].isLike = !data.value.rows[i].isLike
|
request(COMMENT_PRAISE, {targetId: d.discussId, type: 5})
|
||||||
const discussSubmitId = data.value.rows[i].discussSubmitId
|
|
||||||
request(DISCUSS_LIKE, {discussSubmitId})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function collection(i) {
|
function collection(d) {
|
||||||
data.value.rows[i].isCollection ? (data.value.rows[i].discussCollectionCount -= 1) : (data.value.rows[i].discussCollectionCount += 1)
|
d.collected ? (d.collectionNum -= 1) : (d.collectionNum += 1)
|
||||||
data.value.rows[i].isCollection = !data.value.rows[i].isCollection
|
d.collected = !d.collected
|
||||||
const discussSubmitId = data.value.rows[i].discussSubmitId
|
request(COMMENT_COLLECTION, {targetId: d.discussId, type: 6})
|
||||||
request(DISCUSS_COLLECTION, {discussSubmitId})
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
64
src/views/login/login.vue
Normal file
64
src/views/login/login.vue
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
<template>
|
||||||
|
<div
|
||||||
|
:style="{
|
||||||
|
margin: 'auto',
|
||||||
|
background:
|
||||||
|
'url(http://img.gz2c.com/FoTcLY8ww-ISCFlwyCoYuLim1BMt) no-repeat',
|
||||||
|
backgroundSize: '100% 100%',
|
||||||
|
width: '100%',
|
||||||
|
height: '100vh',
|
||||||
|
display: 'flex',
|
||||||
|
}"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
:style="{
|
||||||
|
width: '300px',
|
||||||
|
height: '300px',
|
||||||
|
margin: '10% auto',
|
||||||
|
padding: '20px 30px',
|
||||||
|
textAlign: 'center',
|
||||||
|
borderRadius: '10px',
|
||||||
|
background: '#e0e0e0',
|
||||||
|
boxShadow: '20px 20px 60px #bebebe,-20px -20px 60px #ffffff',
|
||||||
|
}"
|
||||||
|
>
|
||||||
|
<div :style="{ fontSize: '24px', paddingBottom: '30px' }">用户登录</div>
|
||||||
|
<div>
|
||||||
|
<input placeholder="用户名" v-model="form.account"/>
|
||||||
|
<input
|
||||||
|
placeholder="密码"
|
||||||
|
v-model="form.password"
|
||||||
|
:style="{ marginTop: '30px' }"
|
||||||
|
type="password"
|
||||||
|
/>
|
||||||
|
<button :style="{ marginTop: '30px' }" @click="loginUser">
|
||||||
|
登录
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<script setup>
|
||||||
|
import {useRouter} from "vue-router";
|
||||||
|
import {ref} from "vue";
|
||||||
|
import {LOGIN} from "@/api/api";
|
||||||
|
import {setCookie} from "@/api/utils";
|
||||||
|
import {request} from "@/api/request";
|
||||||
|
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
const form = ref({
|
||||||
|
account: "10181457",
|
||||||
|
password: "1234567890Aa",
|
||||||
|
});
|
||||||
|
|
||||||
|
async function loginUser() {
|
||||||
|
const {data:token} = await request(LOGIN, form.value);
|
||||||
|
console.log(2222222222)
|
||||||
|
console.log(token)
|
||||||
|
setCookie("token", token, 10);
|
||||||
|
await router.push({path: "/BallotPage"});
|
||||||
|
// location.reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
Reference in New Issue
Block a user