hookehuyr

创建主办方业务逻辑优化

1 /* 1 /*
2 * @Date: 2022-10-14 17:26:56 2 * @Date: 2022-10-14 17:26:56
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2022-10-21 22:59:04 4 + * @LastEditTime: 2022-10-22 00:24:38
5 * @FilePath: /swx/src/api/Host/index.js 5 * @FilePath: /swx/src/api/Host/index.js
6 * @Description: 活动相关接口 6 * @Description: 活动相关接口
7 */ 7 */
...@@ -10,6 +10,7 @@ import { fn, fetch } from '../fn'; ...@@ -10,6 +10,7 @@ import { fn, fetch } from '../fn';
10 const Api = { 10 const Api = {
11 HOST_LIST: '/srv/?a=host_list', 11 HOST_LIST: '/srv/?a=host_list',
12 HOST_INFO: '/srv/?a=host_info', 12 HOST_INFO: '/srv/?a=host_info',
13 + HOST_ADD: '/srv/?a=host_add',
13 HOST_EDIT: '/srv/?a=host_edit', 14 HOST_EDIT: '/srv/?a=host_edit',
14 HOST_DELETE: '/srv/?a=host_del', 15 HOST_DELETE: '/srv/?a=host_del',
15 ACTIVITY_ADD: '/srv/?a=activity_add', 16 ACTIVITY_ADD: '/srv/?a=activity_add',
...@@ -31,6 +32,12 @@ export const hostListAPI = (params) => fn(fetch.get(Api.HOST_LIST, params)); ...@@ -31,6 +32,12 @@ export const hostListAPI = (params) => fn(fetch.get(Api.HOST_LIST, params));
31 export const hostInfoAPI = (params) => fn(fetch.get(Api.HOST_INFO, params)); 32 export const hostInfoAPI = (params) => fn(fetch.get(Api.HOST_INFO, params));
32 33
33 /** 34 /**
35 + * @description: 新增主办方
36 + * @returns
37 + */
38 +export const addHostAPI = (params) => fn(fetch.post(Api.HOST_ADD, params));
39 +
40 +/**
34 * @description: 修改主办方 41 * @description: 修改主办方
35 * @returns 42 * @returns
36 */ 43 */
......
1 /* 1 /*
2 * @Date: 2022-05-18 22:56:08 2 * @Date: 2022-05-18 22:56:08
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2022-10-18 15:06:40 4 + * @LastEditTime: 2022-10-22 00:12:46
5 * @FilePath: /swx/src/api/fn.js 5 * @FilePath: /swx/src/api/fn.js
6 * @Description: 文件描述 6 * @Description: 文件描述
7 */ 7 */
8 import axios from '@/utils/request'; 8 import axios from '@/utils/request';
9 -import Toast from '@/components/vant-weapp/toast/toast'; 9 +import Taro from '@tarojs/taro'
10 import qs from 'Qs' 10 import qs from 'Qs'
11 11
12 /** 12 /**
...@@ -22,8 +22,11 @@ export const fn = (api) => { ...@@ -22,8 +22,11 @@ export const fn = (api) => {
22 } else { 22 } else {
23 // tslint:disable-next-line: no-console 23 // tslint:disable-next-line: no-console
24 console.warn(res); 24 console.warn(res);
25 - if (!res.data.show) return false; 25 + Taro.showToast({
26 - Toast.fail(res.data.msg); 26 + title: res.data.msg,
27 + icon: 'none',
28 + duration: 2000
29 + });
27 return false; 30 return false;
28 } 31 }
29 }) 32 })
...@@ -49,8 +52,11 @@ export const uploadFn = (api) => { ...@@ -49,8 +52,11 @@ export const uploadFn = (api) => {
49 } else { 52 } else {
50 // tslint:disable-next-line: no-console 53 // tslint:disable-next-line: no-console
51 console.warn(res); 54 console.warn(res);
52 - if (!res.data.show) return false; 55 + Taro.showToast({
53 - Toast.fail(res.data.msg); 56 + title: res.data.msg,
57 + icon: 'none',
58 + duration: 2000
59 + });
54 return false; 60 return false;
55 } 61 }
56 }) 62 })
......
1 <!-- 1 <!--
2 * @Date: 2022-09-19 14:11:06 2 * @Date: 2022-09-19 14:11:06
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2022-10-10 10:55:06 4 + * @LastEditTime: 2022-10-22 00:26:20
5 * @FilePath: /swx/src/pages/createProject/index.vue 5 * @FilePath: /swx/src/pages/createProject/index.vue
6 * @Description: 新建主办方页面 6 * @Description: 新建主办方页面
7 --> 7 -->
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
47 <text class="bg-gradient">用户类型</text> 47 <text class="bg-gradient">用户类型</text>
48 </view> 48 </view>
49 <view style="width: 22rem;"> 49 <view style="width: 22rem;">
50 - <van-field :value="add_user_type" label-class="label-class" input-class="input-class" rows="1" autosize label="用户类型" 50 + <van-field :value="add_user_type.name" label-class="label-class" input-class="input-class" rows="1" autosize label="用户类型"
51 type="textarea" placeholder="请输入用户类型(6个字以内)" placeholder-style="color: #999;" customStyle="" inputAlign="" 51 type="textarea" placeholder="请输入用户类型(6个字以内)" placeholder-style="color: #999;" customStyle="" inputAlign=""
52 rightIcon="" :required="true" :border="true" @change="onChangeType" /> 52 rightIcon="" :required="true" :border="true" @change="onChangeType" />
53 <van-row> 53 <van-row>
...@@ -75,7 +75,7 @@ ...@@ -75,7 +75,7 @@
75 <text class="bg-gradient">用户状态</text> 75 <text class="bg-gradient">用户状态</text>
76 </view> 76 </view>
77 <view style="width: 22rem;"> 77 <view style="width: 22rem;">
78 - <van-field :value="add_user_status" label-class="label-class" input-class="input-class" rows="1" autosize label="用户状态" 78 + <van-field :value="add_user_status.name" label-class="label-class" input-class="input-class" rows="1" autosize label="用户状态"
79 type="textarea" placeholder="请输入用户状态(6个字以内)" placeholder-style="color: #999;" customStyle="" inputAlign="" 79 type="textarea" placeholder="请输入用户状态(6个字以内)" placeholder-style="color: #999;" customStyle="" inputAlign=""
80 rightIcon="" :required="true" :border="true" @change="onChangeStatus" /> 80 rightIcon="" :required="true" :border="true" @change="onChangeStatus" />
81 <van-row> 81 <van-row>
...@@ -103,86 +103,83 @@ import { ref } from "vue"; ...@@ -103,86 +103,83 @@ import { ref } from "vue";
103 import { AtInput } from 'taro-ui-vue3' 103 import { AtInput } from 'taro-ui-vue3'
104 import "taro-ui-vue3/dist/style/components/input.scss"; 104 import "taro-ui-vue3/dist/style/components/input.scss";
105 import bottomButton from "@/components/bottom-button"; 105 import bottomButton from "@/components/bottom-button";
106 -import request from '../../utils/request';
107 import Toast from '@/components/vant-weapp/toast/toast'; 106 import Toast from '@/components/vant-weapp/toast/toast';
107 +import { addHostAPI } from '@/api/Host/index';
108 +import { randomId } from '@/utils/tools'
108 109
109 const name = ref(''); 110 const name = ref('');
110 const user_type = ref([]); 111 const user_type = ref([]);
111 const user_status = ref([]); 112 const user_status = ref([]);
112 -const add_user_type= ref(''); 113 +const add_user_type= ref({});
113 -const add_user_status = ref(''); 114 +const add_user_status = ref({});
114 -
115 -const onSave = () => {
116 - if (!name.value) {
117 - Toast.fail('名称不能为空');
118 - return false;
119 - }
120 - let temp_user_type = userType.value.filter(element => element.checked);
121 - user_type.value = temp_user_type.map(element => element.label);
122 - let temp_user_status = userStatus.value.filter(element => element.checked);
123 - user_status.value = temp_user_status.map(element => element.label);
124 - // 保存主办方信息
125 - request.post('/srv/?a=host_add', {
126 - name: name.value,
127 - user_type: user_type.value,
128 - user_status: user_status.value,
129 - })
130 - .then(res => {
131 - if (res.data.code) {
132 - Toast.success('保存成功');
133 - Taro.navigateBack({
134 - delta: 1
135 - });
136 - } else {
137 - console.warn(res.data.msg);
138 - }
139 - })
140 - .catch(err => {
141 - console.error(err);
142 - });
143 -}
144 115
145 const userType = ref([{ 116 const userType = ref([{
117 + key: 'first',
146 label: '首次参与', 118 label: '首次参与',
147 checked: 1, 119 checked: 1,
120 + nop: true
148 }, { 121 }, {
122 + key: 'old',
149 label: '老用户', 123 label: '老用户',
150 checked: 1, 124 checked: 1,
125 + nop: true
151 }]); 126 }]);
152 const userStatus = ref([{ 127 const userStatus = ref([{
128 + key: 'follow',
153 label: '跟踪', 129 label: '跟踪',
154 checked: 1, 130 checked: 1,
131 + nop: true
155 }, { 132 }, {
133 + key: 'guide',
156 label: '引导', 134 label: '引导',
157 checked: 1, 135 checked: 1,
136 + nop: true
158 }]); 137 }]);
159 138
160 139
161 140
162 // 用户类型弹框操作 141 // 用户类型弹框操作
163 const onTapType = (item) => { 142 const onTapType = (item) => {
164 - item.checked = !item.checked 143 + if (item.nop) return false; // 如果是固定字段不能操作
144 + item.checked = !item.checked;
165 } 145 }
146 +
147 +const is_long_press = ref(false); // 是否是长按激活
166 const onLongPressType = (item) => { 148 const onLongPressType = (item) => {
149 + if (item.nop) return false; // 如果是固定字段不能操作
167 show_edit_type.value = true; 150 show_edit_type.value = true;
151 + is_long_press.value = true;
152 + add_user_type.value.key = item.key;
153 + add_user_type.value.name = item.label;
168 } 154 }
169 const show_edit_type = ref(false) 155 const show_edit_type = ref(false)
170 const onChangeType = ({ detail }) => { 156 const onChangeType = ({ detail }) => {
171 - add_user_type.value = detail; 157 + add_user_type.value.name = detail;
172 } 158 }
173 const closeEditType = () => { 159 const closeEditType = () => {
174 show_edit_type.value = false; 160 show_edit_type.value = false;
161 + is_long_press.value = false;
175 } 162 }
176 const confirmEditType = () => { 163 const confirmEditType = () => {
177 if (!add_user_type.value) { 164 if (!add_user_type.value) {
178 Toast.fail('名称不能为空'); 165 Toast.fail('名称不能为空');
179 } else { 166 } else {
180 show_edit_type.value = false; 167 show_edit_type.value = false;
168 + if (is_long_press.value) {
169 + userType.value.forEach(item => {
170 + if (item.key === add_user_type.value.key) { // key值相同
171 + item.label = add_user_type.value.name;
172 + }
173 + });
174 + } else {
181 userType.value.push({ 175 userType.value.push({
182 - label: add_user_type.value, 176 + key: randomId(5),
177 + label: add_user_type.value.name,
183 checked: 1, 178 checked: 1,
184 }); 179 });
185 - add_user_type.value = ''; 180 + }
181 + add_user_type.value = {};
182 + is_long_press.value = false;
186 } 183 }
187 } 184 }
188 const addSign = () => { 185 const addSign = () => {
...@@ -191,10 +188,17 @@ const addSign = () => { ...@@ -191,10 +188,17 @@ const addSign = () => {
191 188
192 // 用户状态 189 // 用户状态
193 const onTapStatus = (item) => { 190 const onTapStatus = (item) => {
194 - item.checked = !item.checked 191 + if (item.nop) return false; // 如果是固定字段不能操作
192 + item.checked = !item.checked;
195 } 193 }
194 +
195 +const is_long_press_status = ref(false); // 是否是长按激活
196 const onLongPressStatus = (item) => { 196 const onLongPressStatus = (item) => {
197 + if (item.nop) return false; //如果是固定字段不能操作
197 show_edit_status.value = true; 198 show_edit_status.value = true;
199 + is_long_press_status.value = true;
200 + add_user_status.value.key = item.key;
201 + add_user_status.value.name = item.label;
198 } 202 }
199 const show_edit_status= ref(false) 203 const show_edit_status= ref(false)
200 const onChangeStatus = ({ detail }) => { 204 const onChangeStatus = ({ detail }) => {
...@@ -202,23 +206,55 @@ const onChangeStatus = ({ detail }) => { ...@@ -202,23 +206,55 @@ const onChangeStatus = ({ detail }) => {
202 } 206 }
203 const closeEditStatus = () => { 207 const closeEditStatus = () => {
204 show_edit_status.value = false; 208 show_edit_status.value = false;
209 + is_long_press_status.value = false;
205 } 210 }
206 const confirmEditStatus = () => { 211 const confirmEditStatus = () => {
207 if (!add_user_status.value) { 212 if (!add_user_status.value) {
208 Toast.fail('名称不能为空'); 213 Toast.fail('名称不能为空');
209 } else { 214 } else {
210 show_edit_status.value = false; 215 show_edit_status.value = false;
216 + if (is_long_press.value) {
217 + userStatus.value.forEach(item => {
218 + if (item.key === add_user_status.value.key) { // key值相同
219 + item.label = add_user_status.value.name;
220 + }
221 + });
222 + } else {
211 userStatus.value.push({ 223 userStatus.value.push({
224 + key: randomId(5),
212 label: add_user_status.value, 225 label: add_user_status.value,
213 checked: 1, 226 checked: 1,
214 }) 227 })
215 - add_user_status.value = ''; 228 + }
229 + add_user_status.value = {};
230 + is_long_press_status.value = false;
216 } 231 }
217 } 232 }
218 const addStatus = () => { 233 const addStatus = () => {
219 show_edit_status.value = true; 234 show_edit_status.value = true;
220 } 235 }
221 236
237 +const onSave = async () => {
238 + if (!name.value) {
239 + Toast.fail('名称不能为空');
240 + return false;
241 + }
242 + let temp_user_type = userType.value.filter(element => element.checked && !element.nop);
243 + user_type.value = temp_user_type.map(element => element.label);
244 + let temp_user_status = userStatus.value.filter(element => element.checked && !element.nop);
245 + user_status.value = temp_user_status.map(element => element.label);
246 + // 新增主办方信息
247 + const params = {
248 + name: name.value,
249 + user_type: JSON.stringify(user_type.value),
250 + user_status: JSON.stringify(user_status.value),
251 + }
252 + const { code, data } = await addHostAPI(params);
253 + if (code) {
254 + Toast.success('新增成功');
255 + Taro.navigateBack();
256 + }
257 +}
222 </script> 258 </script>
223 259
224 <script> 260 <script>
......
1 <!-- 1 <!--
2 * @Date: 2022-09-19 14:11:06 2 * @Date: 2022-09-19 14:11:06
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2022-10-21 23:42:11 4 + * @LastEditTime: 2022-10-22 00:22:28
5 * @FilePath: /swx/src/pages/editProject/index.vue 5 * @FilePath: /swx/src/pages/editProject/index.vue
6 * @Description: 新建主办方页面 6 * @Description: 新建主办方页面
7 --> 7 -->
...@@ -103,12 +103,10 @@ import { ref, onMounted } from "vue"; ...@@ -103,12 +103,10 @@ import { ref, onMounted } from "vue";
103 import { AtInput } from 'taro-ui-vue3' 103 import { AtInput } from 'taro-ui-vue3'
104 import "taro-ui-vue3/dist/style/components/input.scss"; 104 import "taro-ui-vue3/dist/style/components/input.scss";
105 import bottomButton from "@/components/bottom-button"; 105 import bottomButton from "@/components/bottom-button";
106 -import request from '../../utils/request';
107 import Toast from '@/components/vant-weapp/toast/toast'; 106 import Toast from '@/components/vant-weapp/toast/toast';
108 import { hostInfoAPI, editHostAPI } from '@/api/Host/index'; 107 import { hostInfoAPI, editHostAPI } from '@/api/Host/index';
109 import { getCurrentPageParam } from "@/utils/weapp"; 108 import { getCurrentPageParam } from "@/utils/weapp";
110 import { randomId } from '@/utils/tools' 109 import { randomId } from '@/utils/tools'
111 -import { json } from 'stream/consumers';
112 110
113 111
114 onMounted(async () => { 112 onMounted(async () => {
......