HEX
Server: Apache/2.4.59 (Debian)
System: Linux keymana 4.19.0-21-cloud-amd64 #1 SMP Debian 4.19.249-2 (2022-06-30) x86_64
User: lijunjie (1003)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/dk/wp-content/themes/food/page-creating_activity_page.php
<?php
/* Template Name: creating_activity_page  */
//$tangDomain = "https://app.tangchinese.org/wp-content/themes/classapp/";
?>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>creating_activity_page</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0,user-scalable=no">

    <!--    <script src="-->
    <?php //echo get_template_directory_uri(); ?><!--/assets/customized_web/js/vue.min.js"></script>-->
<!--    <script src="--><?php //echo $tangDomain; ?><!--/assets/customized_web/js/vue.min.js"></script>-->
<!--    <script src="--><?php //echo $tangDomain; ?><!--/assets/customized_web/js/vue.min.js"></script>-->
<!--    <script src="--><?php //echo $tangDomain; ?><!--/assets/customized_web/js/axios.min.js"></script>-->
<!--    <script src="--><?php //echo $tangDomain; ?><!--/assets/customized_web/js/qs.js"></script>-->
<!--    <link href="--><?php //echo $tangDomain; ?><!--/assets/customized_web/css/antd.min.css" rel="stylesheet">-->
<!--    <script src="--><?php //echo $tangDomain; ?><!--/assets/customized_web/js/moment.min.js"></script>-->

    <script src="<?php echo get_template_directory_uri(); ?>/food-app/ranking/creating_page_js/vue.min.js"></script>
    <script src="<?php echo get_template_directory_uri(); ?>/food-app/ranking/creating_page_js/vue.min.js"></script>
    <script src="<?php echo get_template_directory_uri(); ?>/food-app/ranking/creating_page_js/axios.min.js"></script>
    <script src="<?php echo get_template_directory_uri(); ?>/food-app/ranking/creating_page_js/qs.js"></script>
    <link href="<?php echo get_template_directory_uri(); ?>/food-app/ranking/creating_page_js/antd.min.css" rel="stylesheet">
    <script src="<?php echo get_template_directory_uri(); ?>/food-app/ranking/creating_page_js/moment.min.js"></script>

    <style>
        img {
            max-width: 100%;
            height: auto;

        }

        #app {

            padding: 3px;
        }
    </style>
</head>
<body>
<div id="app">

    <?php

    $type0Str = <<<EOF
    <div style="height: 20px"></div>
    <p>Id:</p>
    <a-input v-model="id" disabled></a-input>


    <div style="height: 20px"></div>
    <p>标题:</p>
    <a-input v-model="name" :disabled="textFieldDisabled"></a-input>



    <div style="height: 20px"></div>
    <p>简介:</p>
    <a-input v-model="content" :disabled="textFieldDisabled"></a-input>
    
    <div style="height: 20px"></div>
<!--    <p>start_date: {{start_date}}</p>-->
    <p>start_date: </p>
    <a-input v-model="start_date" :disabled="textFieldDisabled" type="datetime-local"></a-input>
    
    <div style="height: 20px"></div>
<!--    <p>end_date: {{end_date}}</p>-->
    <p>end_date: </p>
    <a-input v-model="end_date" :disabled="textFieldDisabled" type="datetime-local"></a-input>

        <div style="height: 20px"></div>
        <p>Status:</p>
        <a-radio-group v-model="radioValue" @change="onChange" :disabled="textFieldDisabled">
        <a-radio :value="0">
                待审核
            </a-radio>
            <a-radio :value="1">
                上架
            </a-radio>
<!--             <a-radio :value="99">-->
<!--                已删除-->
<!--            </a-radio>-->
       </a-radio-group>
EOF;
    echo $type0Str;
    ?>

    <div style="height: 20px"></div>
    <p>Activity Image:</p>
    <img alt="img_url" style="width: 100%" :src="img_url"/>
    <div style="height: 10px"></div>
    <div class="clearfix">
        <a-upload :file-list="fileList" :remove="handleRemove" :before-upload="beforeUpload">
            <a-button style="width:200px;">
                Select Image
                <a-icon type="upload"/>
                Select Image
            </a-button>
        </a-upload>
        <a-button
                type="primary"
                :disabled="fileList.length === 0"
                :loading="uploading"
                style="margin-top: 16px"
                @click="uploadHandleChange"
        >
            {{ uploading ? 'Uploading' : 'Start Upload' }}
        </a-button>
    </div>

    <div style="height: 50px"></div>
    <div style=" display: flex;
      justify-content: center;
      align-items: center;">

        <!--        <a-button v-show="!has_customize" @click="submitForm" type="primary">Submit</a-button>-->
        <!---->
        <!--        <a-button @click="changeFormState" v-show="has_customize" :disabled="!textFieldDisabled">Edit Info</a-button>-->
        <!--        <div style="width: 30px"></div>-->
        <!--        <a-button @click="submitForm" v-show="has_customize" :disabled="textFieldDisabled" type="primary">Confirm-->
        <!--            Submission-->
        <!--        </a-button>-->

        <a-button @click="submitForm" type="primary">Confirm Submission</a-button>
    </div>


    <div style="height: 50px"></div>
</div>

<script>
    const app = {
        el: "#app",
        data() {
            return {
                token: '',

                action: 'update',
                id: '0',

                name: "",
                content: "",
                start_date: "0000-00-00 00:00:00",
                end_date: "0000-00-00 00:00:00",

                score: "0",

                status: "1",

                user_id: "0",
                user_name: "",


                img_id: '0',
                img_url: '',
                img_id_has_uploaded: false,

                radioValue: 0,

                has_customize: false,
                textFieldDisabled: false,


                fileList: [],
                uploading: false,

            }
        },
        computed: {
            //自定义请求头
            headers() {
                return {
                    'Authorization': 'Bearer ' + this.token,
                }
            }
        },

        mounted() {
            // let id = this.$route.query.id;
            // this.type = this.getQueryString("type"); //参数名1
            this.id = this.getQueryString("id"); //参数名1
            console.log("id => ", this.id);

            if (window.localStorage) {
                console.log("This browser supports localStorage");
                // alert('This browser supports localStorage');
            } else {
                alert('This browser does NOT support localStorage');
            }

            // localStorage.user_id = 3; // this.user_id;
            this.user_id = localStorage.user_id;
            // this.user_id = this.getQueryString("user_id");
            console.log('user_id => ' + this.user_id);
            this.user_name = localStorage.user_name;
            console.log('user_name => ' + this.user_name);

            // this.token = this.getQueryString("token");
            // console.log('token => ' + this.token);

            this.action = this.getQueryString("action");
            console.log('action => ' + this.action);

            if (this.action === 'update') {
                this.initForm();
            }
        },
        methods: {
            changeFormState() {
                this.textFieldDisabled = !this.textFieldDisabled;
            },
            submitForm() {

                this.status = this.radioValue
                const up_img_id = this.img_id_has_uploaded ? this.img_id : null;

                // var stringTime = this.start_date; //'2012-10-12 22:37:33';
                // var timestamp = Date.parse(new Date(stringTime));
                // var live_timestamp = timestamp / 1000;
                // // console.log(timestamp + '就是' + stringTime + '时间戳 ' + live_timestamp);
                // console.log(stringTime + ' 时间戳 => ' + live_timestamp);

                // console.log(this.start_date + ' 处理前 => ' + this.end_date);
                this.start_date = this.date2Db(this.start_date)
                this.end_date = this.date2Db(this.end_date)
                console.log(this.start_date + ' 处理后 => ' + this.end_date);

                let formData = {
                    'module': 'ranking',
                    'action': 'index',
                    'a': 'setActivity',

                    'func_action': this.action,

                    'id': this.id,

                    'type': '0',

                    'form_name': this.name,
                    'content': this.content,

                    'start_date': this.start_date,
                    'end_date': this.end_date,

                    'img_id': up_img_id,
                    'img_url': this.img_url,

                    'status': this.status,

                    // 'debugmod': 1,
                }

                if (this.action === 'add') {
                    formData['user_id'] = this.user_id
                    formData['user_name'] = this.user_name
                }

                console.log(' formData => ');
                console.log(formData);

                axios({
                    method: 'post',
                    // headers: {
                    //     'Authorization': 'Bearer ' + this.token,
                    // },
                    url: '/api/',
                    data: Qs.stringify(formData)
                })
                    .then((response) => {
                        // console.log(response);
                        let data = response.data
                        if (data.rc === 0) {

                            if (this.action === 'add') {
                                // let backData = data.data;
                                this.id = data.id;

                                console.log('add done id =>' + this.id);
                            }

                            this.action = 'update';

                            antd.notification.success({
                                message: 'Submit Success',
                            });

                            this.initForm()
                        }
                    })
                    .catch(function (error) {
                        console.log(error);
                    });
            },

            initForm() {
                axios({
                    method: 'post',
                    // url: '//dk.smart1space.site/api',
                    url: '/api',
                    data: Qs.stringify({
                        'module': 'ranking',
                        'action': 'index',
                        'a': 'getActivityListInfoByPage',
                        id: this.id,

                        pageNum: 1,
                        pageSize: 1,
                    })
                    // , headers: {
                    //     'Authorization': 'Bearer ' + this.token,
                    // }
                })
                    .then((response) => {
                        // console.log(response);
                        let data = response.data
                        // console.log(data);
                        console.log("data.rc => ", data.rc);

                        if (data.rc === 0) {
                            // this.tag_id = data.data.main.tag_id;
                            // this.series_id = data.data.main.id;

                            // console.log("post_data => ", data.data[0]);
                            var post_data = data.data[0];

                            this.id = post_data.id;
                            this.name = post_data.name;
                            this.content = post_data.content;
                            // console.log("post_content => ", this.post_content);

                            // var d = new Date(post_data.live_time * 1000);
                            // console.log("this.live_time date => ", d);
                            //
                            // let live_time = this.formatDate3(d, 'yyyy-mm-dd hh:ii:ss');
                            // console.log(live_time); // 2016-07-06 16:19

                            let start_date_db = post_data.start_date;
                            let start_date_arr = start_date_db.split(" ");
                            this.start_date = start_date_arr[0] + 'T' + start_date_arr[1]
                            // console.log("start_date => ", this.start_date);
                            // str="jpg|bmp|gif|ico|png";


                            //'2017-06-01T08:30:06'
                            this.end_date = this.date2Input(post_data.end_date);// post_data.end_date;
                            // console.log("end_date => ", this.end_date);

                            this.status = post_data.status;

                            this.radioValue = parseInt(this.status);
                            // console.log("status => ", this.status);


                            this.img_id = post_data.img_id;
                            this.img_url = post_data.img_url;
                            // var img_url = post_data.post.img1_url;
                            // if (img_url.startsWith('http')) {
                            //     console.log("字符串是以http开头的!");
                            //
                            //     this.img1_url = img_url.replace("http://", "https://")
                            // } else {
                            //     this.img1_url = img_url;
                            // }

                            this.has_customize = true;
                            this.textFieldDisabled = false;
                        }
                    })
                    .catch(function (error) {
                        console.log(error);
                    });
            },

            // 数据库格式日期 加T  2017-06-01 08:30:06 -> 2017-06-01T08:30:06
            date2Input(inDate) {
                let start_date_arr = inDate.split(" ");
                return start_date_arr[0] + 'T' + start_date_arr[1]
            },

            // input 转 数据库格式日期 去T  2017-06-01T08:30:06 -> 2017-06-01 08:30:06
            date2Db(inDate) {
                let start_date_arr = inDate.split("T");
                return start_date_arr[0] + ' ' + start_date_arr[1]
            },

            //相差日期
            selectTime() {
                var beginTime = $("#inTime").val();
                var endTime = $("#outTime").val();
                var date1 = new Date(beginTime)
                var date2 = new Date(endTime)
                console.log(Math.ceil((date2 - date1) / (86400 * 1000)) + "天")
            },


            formatDate(date, cut) {
                var date = new Date(date);
                var YY = date.getFullYear() + cut;
                var MM =
                    (date.getMonth() + 1 < 10
                        ? "0" + (date.getMonth() + 1)
                        : date.getMonth() + 1) + cut;
                var DD = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
                var hh =
                    (date.getHours() < 10 ? "0" + date.getHours() : date.getHours()) + ":";
                var mm =
                    (date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()) +
                    ":";
                var ss = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
                return YY + MM + DD + " " + hh + mm + ss;
            },

            formatDate3(dateinit, format = 'yyyy-mm-dd hh:ii:ss') {
                let format_str = format
                if (dateinit === null || dateinit === 0 || dateinit === '' || dateinit === undefined) {
                    return ''
                }
                let date = new Date(dateinit)
                //若改为let date = new Date(dateinit / 1000);则dateinit参数仅支持10位的时间戳
                let date_str = {
                    'y+': date.getFullYear(),//年
                    'm+': date.getMonth() + 1, //月份
                    'd+': date.getDate(), //日
                    'h+': date.getHours(), //小时
                    'i+': date.getMinutes(), //分
                    's+': date.getSeconds() //秒
                }
                for (let item in date_str) {
                    if (new RegExp('(' + item + ')', 'i').test(format_str)) {
                        format_str = format_str.replace(
                            RegExp.$1,
                            date_str[item].toString().length < 2 ? '0' + date_str[item] : date_str[item]
                        )
                    }
                }
                return format_str
            },
//     -----------------------------------
// ©著作权归作者所有:来自51CTO博客作者a772304419的原创作品,请联系作者获取转载授权,否则将追究法律责任
//     js日期格式化函数示例:将日期时间格式化成yyyy-mm-dd hh:ii:ss格式
//     https://blog.51cto.com/zhangxueliang/5307568

            /*
                时间格式化
                将 2019-01-01T12:00:00.000+0000 格式化成类似 2019-01-01 12:00:00
                可以指定日期和时间分隔符
                @param datetime 国际化日期格式
                */
            formatWithSeperator(datetime, dateSeprator, timeSeprator) {
                if (datetime != null) {
                    const dateMat = new Date(datetime)
                    const year = dateMat.getFullYear()
                    const month = dateMat.getMonth() + 1
                    const day = dateMat.getDate()
                    const hh = dateMat.getHours()
                    const mm = dateMat.getMinutes()
                    const ss = dateMat.getSeconds()
                    const timeFormat = year + dateSeprator + month + dateSeprator + day + ' ' + hh + timeSeprator + mm + timeSeprator + ss
                    return timeFormat
                }
            },

            //         作者:Eirmood
            // 链接:https://www.jianshu.com/p/4aef8a993013
            //     来源:简书
            // 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

            getQueryString(name) {
                let reg = `(^|&)${name}=([^&]*)(&|$)`
                let r = window.location.search.substr(1).match(reg);
                if (r != null) return unescape(r[2]);
                return null;
            }
            ,

            onChange(e) {
                console.log('radio checked', e.target.value);
            }
            ,

            beforeUpload(file) {
                const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png';
                if (!isJpgOrPng) {
                    this.$message.error('You can only upload JPG file!');
                }
                const isLt8M = file.size / 1024 / 1024 < 8;
                if (!isLt8M) {
                    this.$message.error('Image must smaller than 8MB!');
                }
                // return isJpgOrPng && isLt8M;

                this.fileList = [...this.fileList, file];
                // return false;
                return isJpgOrPng && isLt8M;
            }
            ,

            handleRemove(file) {
                const index = this.fileList.indexOf(file);
                const newFileList = this.fileList.slice();
                newFileList.splice(index, 1);
                this.fileList = newFileList;
            }
            ,


            uploadHandleChange() {
                // const {fileList} = this;
                // const formData = new FormData();
                // fileList.forEach(file => {
                //     formData.append('files[]', file);
                // });
                this.uploading = true;

                // let file = e.target.files[0]
                let file = this.fileList[0]
                /* eslint-disable no-undef */
                let param = new FormData()  // 创建form对象
                param.append('images', file)  // 通过append向form对象添加数据
                param.append('user_id', this.user_id) // 添加form表单中其他数据
                param.append('img_upload_verify', 'imgE5FCDG3HQA4B1NOPIJ2RSTUV67KL') // 添加form表单中其他数据

                // console.log(param.get('tang_file')) // FormData私有类对象,访问不到,可以通过get判断值是否传进去
                let config = {
                    headers: {'Authorization': 'Bearer ' + this.token}
                }
                // axios.post('https://app.tangchinese.org/api-app-data?module=upload&action=upload_app', param, config)
                axios.post('<?php echo $domain_url; ?>' + '/wp_upload_img', param, config)
                    .then(response => {
                        // console.log(response)
                        console.log(response.data)

                        var model = response.data;

                        if (model.rc == 0) {
                            this.img_id = model.id;
                            this.img_url = model.url;

                            this.uploading = false;
                            this.img_id_has_uploaded = true;

                            antd.notification.success({
                                message: 'upload successfully.',
                            });
                        } else {
                            antd.notification.error({
                                message: 'upload failed.',
                            });
                        }
                    })
                    .catch(error => {
                        console.log(error)
                        antd.notification.error({
                            message: 'upload failed.',
                        });
                    })
            }
            ,

        },
    }


    function init() {
        new Vue(app)
    }
</script>
<script src="<?php echo get_template_directory_uri(); ?>/food-app/ranking/creating_page_js/antd.min.js" onload="init()"></script>

<!--<script crossorigin="anonymous" integrity="sha384-drFt50yMKg7m1EtWl1ZjDhAePoX+5g30w8Jkc8wnKfEx3GW1qZs2p5iAn03WbRIb" src="https://lib.baomitu.com/antd/1.11.6/antd.js" onload="init()"></script>-->
</body>
</html>