岳鹏龙 1 year ago
parent
commit
bade885783
  1. 21
      src/api/votingElection.ts
  2. 165
      src/manifest.json
  3. 260
      src/pages/myElection/index.vue
  4. 163
      src/pages/votingElection/index.vue

21
src/api/votingElection.ts

@ -1,15 +1,28 @@
import { request } from '@/utils/http'
// 获取投票选举(正在进行)
export function getCategoryData() {
export function getVoteprogress() {
return request.http({
url: '/api/vote_progress'
url: '/api/vote_progress',
method: "GET"
})
}
export function feedback(data: any) {
//用户投票
export function voteMember(data: any) {
return request.http({
url: '/api/t.feedback/add',
url: '/api/vote_member',
data
})
}
// 获取我的选举
export function getMyvote() {
return request.http({
url: '/api/my_vote',
method: "GET"
})
}

165
src/manifest.json

@ -1,38 +1,38 @@
{
"name": "问卷系统",
"appid": "__UNI__1AE1F37",
"description": "v3+ts+uniapp模版",
"versionName": "1.0.68",
"versionCode": 168,
"transformPx": false,
"name" : "问卷系统",
"appid" : "__UNI__4CC99EE",
"description" : "v3+ts+uniapp模版",
"versionName" : "1.0.68",
"versionCode" : 168,
"transformPx" : false,
/* 5+App */
"app-plus": {
"usingComponents": true,
"nvueStyleCompiler": "uni-app",
"compilerVersion": 3,
"splashscreen": {
"alwaysShowBeforeRender": true,
"waiting": true,
"autoclose": true,
"delay": 0
},
"compatible": {
"ignoreVersion": true
"app-plus" : {
"usingComponents" : true,
"nvueStyleCompiler" : "uni-app",
"compilerVersion" : 3,
"splashscreen" : {
"alwaysShowBeforeRender" : true,
"waiting" : true,
"autoclose" : true,
"delay" : 0
},
"compatible" : {
"ignoreVersion" : true
},
/* */
"modules": {
"Barcode": {},
"Camera": {},
"VideoPlayer": {},
"Share": {},
"Geolocation": {},
"Maps": {}
"modules" : {
"Barcode" : {},
"Camera" : {},
"VideoPlayer" : {},
"Share" : {},
"Geolocation" : {},
"Maps" : {}
},
/* */
"distribute": {
"distribute" : {
/* android */
"android": {
"permissions": [
"android" : {
"permissions" : [
"<uses-feature android:name=\"android.hardware.camera\"/>",
"<uses-feature android:name=\"android.hardware.camera.autofocus\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>",
@ -49,86 +49,83 @@
"<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>",
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
],
"minSdkVersion": 21
"minSdkVersion" : 21
},
/* ios */
"ios": {
"dSYMs": false
"ios" : {
"dSYMs" : false
},
/* SDK */
"sdkConfigs": {
"ad": {},
"share": {
"weixin": {
"appid": "wxd448c878a54da98d",
"UniversalLinks": ""
"sdkConfigs" : {
"ad" : {},
"share" : {
"weixin" : {
"appid" : "wx5d1a07b75bd48225",
"UniversalLinks" : ""
}
},
"geolocation": {
"amap": {
"name": "amap_18648278829CcsBXVUm1",
"__platform__": [
"ios",
"android"
],
"appkey_ios": "435934cdfcc901e4872a70391d92cccd",
"appkey_android": "435934cdfcc901e4872a70391d92cccd"
"geolocation" : {
"amap" : {
"name" : "amap_18648278829CcsBXVUm1",
"__platform__" : [ "ios", "android" ],
"appkey_ios" : "37180416cb95db05dc9639e616655a7a",
"appkey_android" : "37180416cb95db05dc9639e616655a7a"
}
},
"maps": {
"amap": {
"name": "amap_18648278829CcsBXVUm1",
"appkey_ios": "435934cdfcc901e4872a70391d92cccd",
"appkey_android": "435934cdfcc901e4872a70391d92cccd"
"maps" : {
"amap" : {
"name" : "amap_18648278829CcsBXVUm1",
"appkey_ios" : "37180416cb95db05dc9639e616655a7a",
"appkey_android" : "37180416cb95db05dc9639e616655a7a"
}
}
},
"icons": {
"android": {
"hdpi": "src/static/logo.png",
"xhdpi": "src/static/logo.png",
"xxhdpi": "src/static/logo.png",
"xxxhdpi": "src/static/logo.png"
"icons" : {
"android" : {
"hdpi" : "src/static/logo.png",
"xhdpi" : "src/static/logo.png",
"xxhdpi" : "src/static/logo.png",
"xxxhdpi" : "src/static/logo.png"
}
},
"splashscreen": {
"iosStyle": "common",
"androidStyle": "default",
"android": {
"hdpi": "",
"xhdpi": "",
"xxhdpi": ""
"splashscreen" : {
"iosStyle" : "common",
"androidStyle" : "default",
"android" : {
"hdpi" : "",
"xhdpi" : "",
"xxhdpi" : ""
},
"ios": {
"storyboard": "C:/Users/Lenovo/Desktop/CustomStoryboard.zip"
"ios" : {
"storyboard" : "C:/Users/Lenovo/Desktop/CustomStoryboard.zip"
}
}
}
},
/* */
"quickapp": {},
"quickapp" : {},
/* */
"mp-weixin": {
"appid": "wx5d1a07b75bd48225",
"setting": {
"urlCheck": false,
"es6": true,
"postcss": false,
"minified": true
"mp-weixin" : {
"appid" : "wx5d1a07b75bd48225",
"setting" : {
"urlCheck" : false,
"es6" : true,
"postcss" : false,
"minified" : true
},
"usingComponents": true
"usingComponents" : true
},
"mp-alipay": {
"usingComponents": true
"mp-alipay" : {
"usingComponents" : true
},
"mp-baidu": {
"usingComponents": true
"mp-baidu" : {
"usingComponents" : true
},
"mp-toutiao": {
"usingComponents": true
"mp-toutiao" : {
"usingComponents" : true
},
"uniStatistics": {
"enable": false
"uniStatistics" : {
"enable" : false
},
"vueVersion": "3"
"vueVersion" : "3"
}

260
src/pages/myElection/index.vue

@ -1,19 +1,17 @@
<template>
<view class="container">
<scroll-view class="scroll-view" scroll-y @scrolltolower="loadMore" :show-scrollbar="false">
<view v-for="(item, index) in electionList" :key="index" class="election-item">
<view class="year-title">
<view class="headpart">
<text class="title">{{ item.title }}</text>
<view
class="type"
:style="
<view class="type" :style="
item.type == '投票中'
? 'background: #DBEAFE;color: #3B82F6;'
: item.type == '当选'
? 'background: #DCFCE7;color: #10B981'
: 'background: #F3F4F6;color: #4B5563'
"
>
">
{{ item.type }}
</view>
</view>
@ -22,12 +20,11 @@
<view style="display: grid">
<view
v-for="(candidate, cIndex) in item.candidates.slice(0, expandedStates[index] ? item.candidates.length : 1)"
:key="cIndex"
class="candidate-item"
>
:key="cIndex" class="candidate-item">
<view class="info-section">
<view style="display: flex; align-items: center">
<img style="width: 96rpx; height: 96rpx; border-radius: 50%" :src="item.img" alt="" />
<img style="width: 96rpx; height: 96rpx; border-radius: 50%" :src="item.img"
alt="" />
<view style="margin-left: 24rpx; display: grid">
<text class="name">{{ candidate.name }}</text>
<text class="college">{{ candidate.college }}</text>
@ -47,128 +44,42 @@
</view>
</view>
</view>
</scroll-view>
</view>
</template>
<script setup>
import { ref, watch } from 'vue'
const electionList = ref([
{
type: '投票中',
title: '2024学生会主席选举',
candidates: [
{
img: '../../static/redpacket.png',
name: '陈思远',
college: '计算机科学与技术学院',
choice: 1
},
{
img: '../../static/redpacket.png',
name: '陈思远2号',
college: '计算机科学与技术学院',
choice: 0
},
{
img: '../../static/redpacket.png',
name: '陈思远2号',
college: '计算机科学与技术学院',
choice: 2
}
]
},
{
type: '投票中',
title: '2024学生会主席选举',
candidates: [
{
img: '../../static/redpacket.png',
name: '陈思远',
college: '计算机科学与技术学院',
choice: 1
},
{
img: '../../static/redpacket.png',
name: '陈思远2号',
college: '计算机科学与技术学院',
choice: 0
},
{
img: '../../static/redpacket.png',
name: '陈思远2号',
college: '计算机科学与技术学院',
choice: 2
}
]
},
{
type: '投票中',
title: '2024学生会主席选举',
candidates: [
{
img: '../../static/redpacket.png',
name: '陈思远',
college: '计算机科学与技术学院',
choice: 1
},
{
img: '../../static/redpacket.png',
name: '陈思远2号',
college: '计算机科学与技术学院',
choice: 0
},
{
img: '../../static/redpacket.png',
name: '陈思远2号',
college: '计算机科学与技术学院',
choice: 2
}
]
},
{
type: '当选',
title: '2023优秀班干部评选',
candidates: [
{
img: '../../static/redpacket.png',
name: '李雨晴',
college: '工商管理学院',
choice: 0
}
]
},
{
type: '未当选',
title: '2023最佳社团负责人',
candidates: [
{
img: '../../static/redpacket.png',
name: '王浩然',
college: '艺术设计学院',
choice: 2
}
]
}
])
import {
ref,
watch
} from 'vue'
import {
getMyvote
} from '../../api/votingElection'
const electionList = ref([])
const page = ref(1)
const pageSize = ref(10)
const loading = ref(false)
const noMoreData = ref(false)
//
const expandedStates = ref([])
watch(
//
const expandedStates = ref([])
watch(
() => electionList.value,
(newVal) => {
expandedStates.value = newVal.map(() => false)
},
{
}, {
immediate: true
}
)
)
const toggleExpand = (index) => {
const toggleExpand = (index) => {
expandedStates.value[index] = !expandedStates.value[index]
}
}
const choiceClass = (choice) => {
const choiceClass = (choice) => {
switch (choice) {
case 1:
return 'agree'
@ -179,27 +90,56 @@ const choiceClass = (choice) => {
default:
return ''
}
}
}
const choiceText = (choice) => {
return (
{
const choiceText = (choice) => {
return ({
1: '同意',
0: '反对',
2: '弃权'
}[choice] || ''
)
}
} [choice] || '')
}
//
const getList = async () => {
try {
loading.value = true
//
const mockData = await getMyvote().then((res)=> {
})
//
dataList.value = [...dataList.value, ...mockData]
//
noMoreData.value = mockData.length < pageSize.value
} finally {
loading.value = false
}
}
//
const loadMore = () => {
if (loading.value || noMoreData.value) return
page.value += 1
getList()
}
onMounted(() => {
getList()
})
</script>
<style scoped lang="scss">
.container {
.container {
padding: 20rpx;
background-color: #f9fafb;
height: 100vh;
}
}
.election-item {
.election-item {
margin-bottom: 30rpx;
padding: 34rpx;
border-radius: 24rpx;
@ -207,9 +147,9 @@ const choiceText = (choice) => {
box-sizing: border-box;
border: 2rpx solid #f3f4f6;
box-shadow: 0rpx 2rpx 4rpx 0rpx rgba(0, 0, 0, 0.05);
}
}
.year-title {
.year-title {
font-size: 32rpx;
font-weight: bold;
color: #333;
@ -242,91 +182,91 @@ const choiceText = (choice) => {
border-radius: 24rpx;
}
}
}
}
.candidate-item {
.candidate-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 20rpx 0;
}
}
.info-section {
.info-section {
flex: 1;
display: flex;
flex-direction: column;
}
}
.name {
.name {
font-family: Roboto;
font-size: 28rpx;
font-weight: 500;
letter-spacing: normal;
color: #000000;
}
}
.college {
.college {
font-family: Roboto;
font-size: 24rpx;
font-weight: normal;
letter-spacing: normal;
color: #6b7280;
}
}
.choice-tag {
.choice-tag {
display: flex;
justify-content: center;
align-items: center;
font-family: Roboto;
font-size: 28rpx;
font-weight: normal;
}
}
.agree {
.agree {
color: #3b82f6;
}
}
.oppose {
.oppose {
color: #f44336;
}
}
.abstain {
.abstain {
color: #9ca3af;
}
}
.year-title {
.year-title {
display: flex;
justify-content: space-between;
align-items: center;
}
}
.expand-btn {
.expand-btn {
display: flex;
align-items: center;
color: #666;
font-size: 26rpx;
padding: 10rpx 20rpx;
}
}
.arrow {
.arrow {
display: inline-block;
width: 0;
height: 0;
margin-left: 10rpx;
border-left: 10rpx solid transparent;
border-right: 10rpx solid transparent;
}
}
.down {
.down {
border-top: 15rpx solid #999;
}
}
.up {
.up {
border-bottom: 15rpx solid #999;
}
}
/* 优化候选人项间距 */
.candidate-item:last-child {
/* 优化候选人项间距 */
.candidate-item:last-child {
border-bottom: none;
}
}
</style>

163
src/pages/votingElection/index.vue

@ -1,127 +1,134 @@
<script setup lang="ts">
import { getCategoryData } from '../../api/votingElection'
import { getVoteprogress, voteMember } from '../../api/votingElection'
import { getUserList } from '../../api/user'
import useUserStore from '@/store/user'
const userStore = useUserStore()
const doSearch = (_formData: { page: number; limit: number }, onSuccess: Function) => {
// const submitData = { ...formData }
// listApi(submitData, userStore.useType).then((res) => {
// const { data } = res as { data: { data: any; total: number } }
// onSuccess({ data })
// })
const xjList = ref({})
const doSearch = (_formData : { page : number; limit : number }, onSuccess : Function) => {
getVoteprogress().then((res) => {
xjList.value = res.data
res.data.data = res.data.candidate;
// 2.
delete res.data.candidate;
res.data.total = res.data.candidate?.length
const { data } = res as { data : { data : any; total : number } }
onSuccess({ data })
})
onSuccess({
data: {
data: [
{
id: 1,
img: '',
name: '陈志远',
class: '现任财务总监',
yijian: ''
},
{
id: 2,
img: '',
name: '陈志远',
class: '现任财务总监',
yijian: ''
},
{
id: 3,
img: '',
name: '陈志远',
class: '现任财务总监',
yijian: ''
},
{
id: 4,
img: '',
name: '陈志远',
class: '现任财务总监',
yijian: ''
},
{
id: 5,
img: '',
name: '陈志远',
class: '现任财务总监',
yijian: ''
}
],
total: 0
}
})
}
const buttlist = ref([
const buttlist = ref([
{
type: 'agree',
type: '1',
butname: '同意'
},
{
type: 'disagree',
type: '2',
butname: '反对'
},
{
type: 'neutral',
type: '3',
butname: '弃权'
}
])
const selectBut = (data: any, cardid: any, type: string, butname: string) => {
const target = data.find((card: { id: any }) => card.id === cardid)
])
const params = ref([])
const selectBut = (data : any, cardid : any, type : string, butname : string) => {
if (cardid) {
const target = data.find((card : { id : any }) => card.id === cardid)
uni.showModal({
title: '您本轮选举投' + butname + '票',
content: '确定吗?',
success: function (res) {
if (res.confirm) {
if (target) {
target.yijian = target.yijian === type ? null : type
target.vote_result = type
}
} else if (res.cancel) {
console.log('用户点击取消')
}
}
})
params.value.push(target)
} else {
data.forEach((ele : {
vote_result : number; id : any;
}) => {
ele.vote_result = 1
})
}
}
const allChange = () => {
uni.showModal({
title: '您本轮选举全投同意票',
content: '确定吗?',
success: function (res) {
if (res.confirm) {
xjList.value.data?.forEach((ele : { vote_result : number; }) => {
ele.vote_result = 1
})
params.value = xjList.value.data
submit()
} else if (res.cancel) {
console.log('用户点击取消')
}
}
})
}
}
onShow(()=> {
getCategoryData().then((res)=> {
console.log(res,55555555555)
function extractTwoProps(arr:any, key1:string, key2:string) {
return arr.map(({ [key1]: prop1, [key2]: prop2 }) => ({
[key1]: prop1,
[key2]: prop2
}));
}
const submit = () => {
let param = {
openid: userStore.openId,
id: xjList.value.id,
candidate: JSON.stringify(extractTwoProps(params.value,'id','vote_result'))
}
if(param.candidate === '[]') {
uni.showToast({
title: '未选举',
icon: 'none', // 'success', 'loading', 'none'
duration: 1500 // ms
});
} else {
voteMember(param).then((res)=> {
console.log(res,555555555555555)
})
})
}
}
</script>
<template>
<!-- 你的页面内容 -->
<view class="box">
<view class="headpart">
<view class="title">2024年度董事会成员选举</view>
<view class="time">投票开始时间2024年3月15日 18:00</view>
<view class="time">投票截止时间2024年3月15日 18:00</view>
<view class="title">{{ xjList.title }}</view>
<view class="time">投票开始时间{{ xjList.start_time }}</view>
<view class="time">投票截止时间{{ xjList.end_time }}</view>
</view>
<ex-list ref="reListRef" custom-list-type="custom" :on-form-search="doSearch">
<template v-slot="{ data }">
<view class="tppart">
<view class="tpone" v-for="(row, index) of data" :key="'tpone' + index">
<view class="topp">
<img style="width: 96rpx; height: 96rpx; border-radius: 50%" :src="row.img" alt="" />
<img style="width: 96rpx; height: 96rpx; border-radius: 50%" :src="row.photo" alt="" />
<view class="rightpart">
<view class="name">
{{ row.name }}
</view>
<view class="class">
{{ row.class }}
{{ row.position }}
</view>
</view>
</view>
<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)"
:class="{ active: row.yijian === item.type }"
>
:class="{ active: row.vote_result === item.type }">
{{ item.butname }}
</view>
</view>
@ -130,14 +137,14 @@ onShow(()=> {
</template>
</ex-list>
<view class="bottbutton">
<view class="qbty">全部同意</view>
<view class="tjtp">提交投票</view>
<view class="qbty" @click="allChange">全部同意</view>
<view class="tjtp" @click="submit">提交投票</view>
</view>
</view>
</template>
<style scoped lang="scss">
.box {
.box {
width: 100%;
background-color: #f9fafb;
@ -367,5 +374,5 @@ onShow(()=> {
bottom: 0;
border-top: 2rpx solid #ebebec;
}
}
}
</style>
Loading…
Cancel
Save