岳鹏龙 1 year ago
parent
commit
768d90416a
  1. 9
      src/api/votingElection.ts
  2. 61
      src/components/ex-tags/ex-tags.vue
  3. 4
      src/pages/mine/add.vue
  4. 3
      src/pages/mine/index.vue
  5. 5
      src/pages/myElection/index.vue
  6. 102
      src/pages/votingElection/index.vue
  7. 2
      src/store/user.ts

9
src/api/votingElection.ts

@ -1,12 +1,10 @@
import { request } from '@/utils/http' import { request } from '@/utils/http'
// 获取投票选举(正在进行) // 获取投票选举(正在进行)
export function getVoteprogress() { export function getVoteprogress() {
return request.http({ return request.http({
url: '/api/vote_progress', url: '/api/vote_progress',
method: "GET" method: 'GET'
}) })
} }
@ -19,11 +17,10 @@ export function voteMember(data: any) {
} }
// 获取我的选举 // 获取我的选举
export function getMyvote(data:any) { export function getMyvote(data: any) {
return request.http({ return request.http({
url: '/api/my_vote', url: '/api/my_vote',
method: "GET", method: 'GET',
data data
}) })
} }

61
src/components/ex-tags/ex-tags.vue

@ -1,61 +0,0 @@
<template>
<view class="tag_box flex-center-start" :style="{ '--borderColor': borderColor }">
<view class="border" :style="borderStyle" />
<text :style="{ color: labelColor }">{{ label }}</text>
<view class="flex1">
<slot></slot>
</view>
</view>
</template>
<script setup lang="ts">
interface tagsInt {
label: string
labelColor?: string
borderColor?: string
borderType?: 'round' | 'line'
}
const props = withDefaults(defineProps<tagsInt>(), {
label: '收益',
labelColor: '#616161',
borderColor: '#ff8d1a',
borderType: 'line'
})
const borderStyle = computed(() => {
if (props.borderType === 'line') {
return {
width: '8rpx',
height: '28rpx',
marginRight: '16rpx'
}
} else {
return {
width: '16rpx',
height: '16rpx',
marginRight: '13rpx'
}
}
})
</script>
<style scoped lang="scss">
.tag_box {
font-size: 28rpx;
font-weight: 400;
line-height: 40rpx;
--borderColor: #ff8d1a;
.border {
width: 8rpx;
height: 28rpx;
border-radius: 90rpx;
background-color: var(--borderColor);
}
> .flex1 {
padding-left: 20rpx;
}
}
</style>

4
src/pages/mine/add.vue

@ -31,7 +31,9 @@ const onSubmit = uni.$util.debounce(() => {
addAPi(formData).then(() => { addAPi(formData).then(() => {
uni.hideLoading() uni.hideLoading()
uni.switchTab({ url: '/pages/mine/index' }) uni.showToast({ title: '签到成功,等待投票!', icon: 'none' })
setTimeout(() => uni.switchTab({ url: '/pages/mine/index' }), 1000)
}) })
} }
}) })

3
src/pages/mine/index.vue

@ -38,7 +38,7 @@ const updateUserInfo = () => {
userStore.bindUser(list.value[activeKey.value].id as number).then(() => { userStore.bindUser(list.value[activeKey.value].id as number).then(() => {
reset() reset()
userStore.getUserInfo() userStore.getUserInfo()
uni.showToast({ title: '绑定成功', icon: 'none' }) uni.showToast({ title: '签到成功,等待投票!', icon: 'none' })
}) })
} }
@ -79,7 +79,6 @@ const save = () => {
onShow(() => { onShow(() => {
reset() reset()
getAdminPhone().then((res) => { getAdminPhone().then((res) => {
const { data } = res as { data: string } const { data } = res as { data: string }
amdinPhone.value = data || '' amdinPhone.value = data || ''

5
src/pages/myElection/index.vue

@ -15,7 +15,7 @@
: 'background: #F3F4F6;color: #4B5563' : 'background: #F3F4F6;color: #4B5563'
" "
> >
{{ item.vote_title==1?'未开始':(item.vote_title==2?'进行中':'已结束') }} {{ item.vote_title == 1 ? '未开始' : item.vote_title == 2 ? '进行中' : '已结束' }}
</view> </view>
</view> </view>
</view> </view>
@ -34,7 +34,7 @@
<text class="college">{{ candidate.position }}</text> <text class="college">{{ candidate.position }}</text>
</view> </view>
</view> </view>
<view style="display: flex; margin-top: 24rpx;font-family: Roboto;font-size: 14px;color: #4B5563;"> <view style="display: flex; margin-top: 24rpx; font-family: Roboto; font-size: 14px; color: #4b5563">
我的选择 我的选择
<view :class="['choice-tag', choiceClass(candidate.vote_result)]"> <view :class="['choice-tag', choiceClass(candidate.vote_result)]">
{{ choiceText(candidate.vote_result) }} {{ choiceText(candidate.vote_result) }}
@ -137,7 +137,6 @@ const loadMore = () => {
onShow(() => { onShow(() => {
getList() getList()
}) })
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">

102
src/pages/votingElection/index.vue

@ -1,13 +1,13 @@
<script setup lang="ts"> <script setup lang="ts">
import { getVoteprogress, voteMember } from '../../api/votingElection' import { getVoteprogress, voteMember } from '../../api/votingElection'
import useUserStore from '@/store/user' import useUserStore from '@/store/user'
const userStore = useUserStore() const userStore = useUserStore()
const xjList = ref<any>({}) const xjList = ref<any>({})
const doSearch = (_formData : { page : number; limit : number }, onSuccess : Function) => { const doSearch = (_formData: { page: number; limit: number }, onSuccess: Function) => {
getVoteprogress().then((res) => { getVoteprogress().then((res) => {
const { data } = res as { data : { candidate : any[] } } const { data } = res as { data: { candidate: any[] } }
xjList.value = data || {} xjList.value = data || {}
onSuccess({ onSuccess({
data: { data: {
@ -16,9 +16,9 @@
} }
}) })
}) })
} }
const buttlist = ref([ const buttlist = ref([
{ {
type: '1', type: '1',
butname: '同意' butname: '同意'
@ -31,12 +31,12 @@
type: '3', type: '3',
butname: '弃权' butname: '弃权'
} }
]) ])
const params = ref([]) const params = ref([])
const selectBut = (data : any, cardid : any, type : string, butname : string) => { const selectBut = (data: any, cardid: any, type: string, butname: string) => {
if (cardid) { if (cardid) {
const target = data.find((card : { id : any }) => card.id === cardid) const target = data.find((card: { id: any }) => card.id === cardid)
uni.showModal({ uni.showModal({
title: '您本轮选举投' + butname + '票', title: '您本轮选举投' + butname + '票',
content: '确定吗?', content: '确定吗?',
@ -52,18 +52,18 @@
}) })
params.value.push(target) params.value.push(target)
} else { } else {
data.forEach((ele : { vote_result : number; id : any }) => { data.forEach((ele: { vote_result: number; id: any }) => {
ele.vote_result = 1 ele.vote_result = 1
}) })
} }
} }
const allChange = () => { const allChange = () => {
uni.showModal({ uni.showModal({
title: '您本轮选举全投同意票', title: '您本轮选举全投同意票',
content: '确定吗?', content: '确定吗?',
success: function (res) { success: function (res) {
if (res.confirm) { if (res.confirm) {
xjList.value.data?.forEach((ele : { vote_result : number }) => { xjList.value.data?.forEach((ele: { vote_result: number }) => {
ele.vote_result = 1 ele.vote_result = 1
}) })
params.value = xjList.value.candidate params.value = xjList.value.candidate
@ -73,15 +73,15 @@
} }
} }
}) })
} }
function extractTwoProps(arr : any, key1 : string, key2 : string) { function extractTwoProps(arr: any, key1: string, key2: string) {
return arr.map(({ [key1]: prop1, [key2]: prop2 }) => ({ return arr.map(({ [key1]: prop1, [key2]: prop2 }) => ({
[key1]: prop1, [key1]: prop1,
[key2]: prop2 [key2]: prop2
})) }))
} }
const submit = () => { const submit = () => {
let param = { let param = {
openid: userStore.openId, openid: userStore.openId,
id: xjList.value.id, id: xjList.value.id,
@ -94,18 +94,27 @@
duration: 1500 // ms duration: 1500 // ms
}) })
} else { } else {
voteMember(param).then((res) => { voteMember(param)
console.log(res, 555555555555555)
})
}
} }
onShow(() => { }
const showDialog = ref(false)
const navto = (url: string, mode: pageMode = 'navigateTo') => uni.$util.goToPage({ url: url ?? 'pages/index/index', mode })
const isEmptyObject = (obj: any) => {
if (obj == null) return true
if (typeof obj !== 'object' || Array.isArray(obj)) return true
return Reflect.ownKeys(obj).length === 0
}
onShow(() => {
if (userStore.mobile === '') { if (userStore.mobile === '') {
uni.navigateTo({ uni.navigateTo({
url: '/pages/login/login' url: '/pages/login/login'
}) })
} else if (isEmptyObject(userStore.userInfo)) {
showDialog.value = true
} }
}) })
</script> </script>
<template> <template>
@ -132,9 +141,13 @@
</view> </view>
</view> </view>
<view class="bottomp"> <view class="bottomp">
<view class="minbut" v-for="(item, ele) in buttlist" :key="ele" <view
class="minbut"
v-for="(item, ele) in buttlist"
:key="ele"
@click="selectBut(data, row.id, item.type, item.butname)" @click="selectBut(data, row.id, item.type, item.butname)"
:class="{ active: row.vote_result === item.type }"> :class="{ active: row.vote_result === item.type }"
>
{{ item.butname }} {{ item.butname }}
</view> </view>
</view> </view>
@ -147,16 +160,29 @@
<view class="tjtp" @click="submit">提交投票</view> <view class="tjtp" @click="submit">提交投票</view>
</view> </view>
</view> </view>
<view style="display: grid;align-items: center;justify-content: center;width: 100%;height: 100vh;align-content: center;" v-else> <view style="display: grid; align-items: center; justify-content: center; width: 100%; height: 100vh; align-content: center" v-else>
<img style="width: 188px;height: 140px;" src="@/static/img/Group.png" alt="" /> <img style="width: 188px; height: 140px" src="@/static/img/Group.png" alt="" />
<text class="nodata"> <text class="nodata">暂时没有选举 请刷新重试</text>
暂时没有选举 请刷新重试
</text>
</view> </view>
<u-modal
title="提示"
:show="showDialog"
width="650rpx"
:confirm-color="'#2979ff'"
:cancel-color="'#606266'"
:show-confirm-button="true"
:show-cancel-button="false"
:close-on-click-overlay="true"
@confirm="navto('pages/mine/index', 'reLaunch')"
@cancel="showDialog = false"
@close="showDialog = false"
>
请您签到之后再进行投票
</u-modal>
</template> </template>
<style scoped lang="scss"> <style scoped lang="scss">
.box { .box {
width: 100%; width: 100%;
background-color: #f9fafb; background-color: #f9fafb;
@ -386,13 +412,13 @@
bottom: 0; bottom: 0;
border-top: 2rpx solid #ebebec; border-top: 2rpx solid #ebebec;
} }
} }
.nodata { .nodata {
margin-top: 43px; margin-top: 43px;
font-family: Source Han Sans; font-family: Source Han Sans;
font-size: 18px; font-size: 18px;
font-weight: 500; font-weight: 500;
letter-spacing: normal; letter-spacing: normal;
color: #34343F; color: #34343f;
} }
</style> </style>

2
src/store/user.ts

@ -36,7 +36,7 @@ export default defineStore(
.then((res) => { .then((res) => {
const { data } = res as { data: userInfoStoreInt } const { data } = res as { data: userInfoStoreInt }
userInfo.value = data userInfo.value = data || {}
resolve({ code: 1, data, message: 'SUCCESS' }) resolve({ code: 1, data, message: 'SUCCESS' })
}) })

Loading…
Cancel
Save