lefengyang
2026-08-14 b1fcf9eb27ed1b19eeba0880411555f77a69d558
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
<template>
    <view class="page_bg">
        <uv-navbar title="新增模版" :autoBack="true" :placeholder="true" leftIconColor="#fff" bgColor="rgba(0,0,0,0)" titleStyle="color:#fff"></uv-navbar>
        
        <view class="temp">
            <view class="temp_item">
                <view class="title">
                    模版名称
                </view>
                <view class="item">
                    <uv-input placeholder="请输入名称" border="none" v-model="tempName" fontSize="27rpx" customStyle="background: #ECEFF6;padding:18rpx 20rpx;border-radius: 10rpx;"></uv-input>
                </view>
            </view>
            <view class="temp_item">
                <view class="title">
                    屏幕规格
                </view>
                <view class="item">
                    <uv-radio-group v-model="specVal" placement="column">
                        <uv-radio 
                            class="spec_radio"
                            v-for="(item, index) in specList" 
                            :key="index" 
                            :label="item.name" 
                            :name="item.name">
                        </uv-radio>
                    </uv-radio-group>
                </view>
            </view>
            <view class="temp_item">
                <view class="title">
                    动画方式
                </view>
                <view class="item">
                    <uv-radio-group v-model="modeVal" placement="column"  @change="changeMode">
                        <uv-radio 
                            class="spec_radio"
                            v-for="(item, index) in modeList" 
                            :key="index" 
                            :label="item.name" 
                            :name="item.val">
                        </uv-radio>
                    </uv-radio-group>
                </view>
            </view>
 
            <view class="temp_item">
                <view class="title">
                    动画帧数
                </view>
                <view class="item" @click="clickTotal">
                    <uv-input placeholder="请输入" readonly border="none" v-model="total" suffixIcon="arrow-right"
                        suffixIconStyle="color: #bbb" fontSize="26rpx" customStyle="background: #ECEFF6;padding:18rpx 20rpx;border-radius: 10rpx;"></uv-input>
                </view>
            </view>
            <view class="temp_item" v-if="modeVal == 1">
                <view class="title">
                    动画速度
                </view>
                <view class="item" @click="clickSpeed">
                    <uv-input placeholder="请输入" readonly border="none" v-model="speed" suffixIcon="arrow-right"
                        suffixIconStyle="color: #bbb" fontSize="26rpx" customStyle="background: #ECEFF6;padding:18rpx 20rpx;border-radius: 10rpx;"></uv-input>
                </view>
            </view>
            <!-- <view class="temp_item" v-if="modeVal == 1">
                <view class="title">
                    循环次数
                </view>
                <view class="item">
                    <uv-input placeholder="请输入" readonly border="none" v-model="cycle" suffixIcon="arrow-right"
                        suffixIconStyle="color: #bbb" fontSize="26rpx" customStyle="background: #ECEFF6;padding:18rpx 20rpx;border-radius: 10rpx;"></uv-input>
                </view>
            </view> -->
            
            <view class="temp_item1" v-for="(item,index) in total" :key="index">
                <view class="title">
                    动画第{{item}}帧
                </view>
                <view class="item">
                    <uv-button text="编辑" @click="clickGoAnim(item)" shape="circle" size="small" color="linear-gradient( 142deg, #6FD2FF 0%, #268DFF 100%)"></uv-button>
                </view>
            </view>
 
        </view>
        
        
        <!-- <view class="temp_btn" @click="clickGoAnim">
            编辑动画
        </view> -->
        
        <view class="footer_none"></view>
        <view class="footer_btn">
            <uv-button text="保存" color="linear-gradient( 142deg, #6FD2FF 0%, #268DFF 100%)" shape="circle" @click="clickTempleteAdd()"></uv-button>
        </view>
        
        <!-- 动画帧数 -->
        <uv-picker ref="pickerTotal" :columns="columnsTotal" @confirm="confirmTotal"></uv-picker>
        
        <!-- 动画速度 -->
        <uv-picker ref="pickerSpeed" :columns="columnsSpeed" @confirm="confirmSpeed"></uv-picker>
        
    </view>
</template>
 
<script>
    import { templeteAdd } from '@/api/api.js'
    export default {
        data() {
            return {
                tempName: '',
                specList: [{
                    name: '12*24'
                }, {
                    name: '16*24'
                }, {
                    name: '18*24'
                }],
                specVal: '12*24',
                modeList: [
                    {
                        name: '单个动画帧',
                        val: 0
                    },
                    {
                        name: '动画帧切换',
                        val: 1
                    }
                ],
                modeVal: 0,
                columnsTotal: [
                    [2,3,4,5,6,7,8,9]
                ],
                total: 1,
                columnsSpeed: [
                    [10,20,30,40,50,60,70,80,90]
                ],
                speed: 10,
                cycle: 1,
                fpsData: [],
                fpsIndex: 1,
                fpsIds: []
            }
        },
        onLoad() {
 
        },
        onShow() {
            console.log('------onShow')
            const fpsParams = uni.getStorageSync('fpsParams');
            // if (fpsParams) {
            //  console.log('收到回传参数:', fpsParams);
            //  this.fpsIndex = fpsParams.fpsIndex+1
            //  this.fpsData[fpsParams.fpsIndex] = fpsParams.data;
            //  this.fpsIds.push(fpsParams.fpsIndex)
            //  console.log(this.fpsIndex, this.fpsData);
            //  uni.removeStorageSync('fpsParams'); // 清理掉
            // }
            if (fpsParams) {
                console.log('收到回传参数:', fpsParams);
                // 用 splice 代替下标赋值
                this.fpsIndex = fpsParams.fpsIndex+1
                this.fpsData.splice(fpsParams.fpsIndex, 1, fpsParams.data);
                
                if (!this.fpsIds.includes(fpsParams.fpsIndex + 1)) {
                    this.fpsIds.push(fpsParams.fpsIndex + 1);
                }
                console.log(this.fpsIndex, this.fpsData);
                uni.removeStorageSync('fpsParams'); // 清理掉
            }
        },
        methods: {
            clickTempleteAdd(){
                if(!this.tempName){
                    uni.showToast({
                        title: '请输入模版名称',
                        duration: 2000,
                        icon: 'none'
                    });
                    return
                }
                if(this.fpsIds.length == 0){
                    uni.showToast({
                        title: '请编辑动画帧',
                        duration: 2000,
                        icon: 'none'
                    });
                    return
                }
                let totalArr = new Array(this.total).fill(0).map((_, i) => i + 1);
                let diffBA = totalArr.filter(v => !this.fpsIds.includes(v));
                console.log(totalArr, diffBA)
                if(diffBA.length != 0){
                    uni.showToast({
                        title: '请编辑第'+ Math.min(...diffBA) +'帧',
                        duration: 2000,
                        icon: 'none'
                    });
                    return
                }
                
                templeteAdd({
                    name: this.tempName,
                    userId: uni.getStorageSync('userId'),
                    screen: this.specVal, //屏幕
                    fpsTotal: this.total, //总帧数
                    speed: this.speed, //速度
                    
                    fpsData: JSON.stringify(this.fpsData)
                }).then(res=>{
                    console.log('添加动画模版',res)
                    uni.showToast({
                        title: res.msg,
                        duration: 2000,
                        icon: 'none'
                    });
                    if(res.code == 200){
                        uni.navigateBack({
                            delta: 1
                        });
                    }
                })
            },
            clickSpeed(){
                this.$refs.pickerSpeed.open();
            },
            confirmSpeed(e) {
                console.log('confirmSpeed', e.value[0]);
                this.speed = e.value[0]
            },
            clickTotal(){
                if(this.total != 1){
                    this.$refs.pickerTotal.open();
                }
            },
            confirmTotal(e) {
                console.log('confirmTotal', e.value[0]);
                this.total = e.value[0]
            },
            changeMode(e){
                if(e == 0){
                    this.total = 1
                }
                else{
                    this.total = 2
                }
                this.fpsIndex = 1
                this.fpsData = []
            },
            clickGoAnim(index){
                console.log(this.fpsIndex, index)
                // if(this.fpsIndex > index){
                //  uni.showToast({
                //      title: '请先编辑第'+this.fpsIndex+'帧',
                //      duration: 2000,
                //      icon: 'none'
                //  });
                //  return
                // }
                uni.navigateTo({
                    url: '/pages/animation/animation?fps='+index
                })
            }
        }
    }
</script>
 
<style lang="scss" scoped>
.footer_none{
    height: 200rpx;
}
.footer_btn{
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: #fff;
    padding:30rpx 40rpx;
}
.temp_btn{
    position: fixed;
    left: 30rpx;
    bottom: 60rpx;
    right: 30rpx;
    box-sizing: border-box;
    height: 96rpx;
    background: linear-gradient( 142deg, #6FD2FF 0%, #268DFF 100%);
    border-radius: 385rpx 385rpx 385rpx 385rpx;
    font-size: 30rpx;
    color: #FFFFFF;
    line-height: 96rpx;
    text-align: center;
}
.spec_radio{
    margin-top: 30rpx;
    &:first-child{
        margin-top: 10rpx;
    }
}
.temp{
    padding:0 30rpx;
    .temp_item1{
        display: flex;
        align-items: center;
        justify-content: space-between;
        background: linear-gradient( 180deg, #FFFFFF 0%, rgba(255,255,255,0.5) 100%);
        box-shadow: 8rpx 8rpx 23rpx 0rpx rgba(67,147,248,0.1), -8rpx -8rpx 23rpx 0rpx rgba(255,255,255,0.4);
        border-radius: 23rpx 23rpx 23rpx 23rpx;
        border: 2rpx solid #FFFFFF;
        padding:30rpx;
        box-sizing: border-box;
        margin-top: 24rpx;
        .title{
            flex-shrink: 0;
            font-size: 30rpx;
            color: rgba(0,0,0,0.9);
            line-height: 40rpx;
            
        }
        .item{
            
        }
    }
    .temp_item{
        background: linear-gradient( 180deg, #FFFFFF 0%, rgba(255,255,255,0.5) 100%);
        box-shadow: 8rpx 8rpx 23rpx 0rpx rgba(67,147,248,0.1), -8rpx -8rpx 23rpx 0rpx rgba(255,255,255,0.4);
        border-radius: 23rpx 23rpx 23rpx 23rpx;
        border: 2rpx solid #FFFFFF;
        padding:30rpx;
        box-sizing: border-box;
        margin-top: 24rpx;
        .title{
            flex-shrink: 0;
            font-size: 30rpx;
            color: rgba(0,0,0,0.9);
            line-height: 40rpx;
        }
        .item{
            margin-top: 15rpx;
        }
    }
}
.page_bg{
    width: 100%;
    min-height: calc(100vh - var(--window-bottom));
    background:url('/static/img/bg_2.jpg') no-repeat center top;
    background-size: 100% auto;
}
</style>