Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tt小程序中如果不在js文件中引入css,css不会生效 #2057

Closed
w22296437978 opened this issue Jan 26, 2019 · 3 comments
Closed

tt小程序中如果不在js文件中引入css,css不会生效 #2057

w22296437978 opened this issue Jan 26, 2019 · 3 comments
Labels
question Further information is requested

Comments

@w22296437978
Copy link

image

import "taro-ui/dist/style/components/form.scss"
import "taro-ui/dist/style/components/input.scss"
import "taro-ui/dist/style/components/checkbox.scss"
import { AtForm,AtInput,AtButton,AtCheckbox } from 'taro-ui'
import Taro, { Component } from '@tarojs/taro'
import { View } from '@tarojs/components'

import './index.css'
import '../../../app.css'
import noimg from '../../../images/noimg1.png'





export default class CForm extends Component {

    constructor(props) {
        super(props)
        this.state = {
            h_margin: 0,
            w_margin: 10,
            bg_color: "#fff",
            button: {
                bg_color: "#06a0fd",
                borderRadius: 0,
                font_size: 26,
                height: 45,
                name: "提交",
                name_color: "#fff",
                targetType: "",
                targetUrl: "",
                w_margin: 100,
                width: 100
            },
            form:{},
            required:[],
            jSub:[]
        }
        
        
    }

    componentWillMount() {
    }
    componentDidMount() {
       
        this.setState(this.props.props ? JSON.parse(this.props.props) : {})
        const {sub} = this.props
        // 不能修改props上面的值
        const jSub = []
        // // console.error("组件内部获取参数-》",sub);
        
        for (let i = 0; i < sub.length; i++) {
            const ele = sub[i]
            jSub[i] = {}
            Object.assign(jSub[i],ele)
            // 解析字符串
            jSub[i].props = JSON.parse(ele.props)
            const jEle = jSub[i] 
            if(jEle.name=="choose"){
                const form =this.state.form
                form[jEle.props.name]=[]
                // 转换为自定义组件支持的形式
                for (let j = 0; j < jEle.props.data.length; j++) {
                    const item = jEle.props.data[j]
                    item.label = item.name
                    item.value = 'value'+j
                    if(item.select){
                        // 将选择的参数放到form
                        this.state.form[jEle.props.name].push(item.value)
                    }
                }
            }
            // 每个元素的子元素
            const cs =  jEle.props.data
            if(cs){
                for (let j = 0; j < cs.length; j++) {
                    if(cs[j].required)
                    // 保存必须的参数名
                        this.state.required.push(cs[j].name)               
                }
            }
        }
        this.setState({jSub}) 
    }

    componentWillUnmount() { }

    componentDidShow() {
    }
    onSubmit (e) {
        e&&e.stopPropagation&&e.stopPropagation() // 阻止事件冒泡
        console.debug(this.state.form);
        console.debug(this.state.required);
        
    }
    onReset (e) {
        e&&e.stopPropagation&&e.stopPropagation() // 阻止事件冒泡
        // DONE 直接清空form的话会有问题
        const form = Object.assign({},this.state.form);
        for (const key in form) {
            if (form.hasOwnProperty(key)) {
                if(form[key] instanceof Array) form[key]=[]
                else if(form[key] instanceof Object) form[key]={}
                else form[key] =''
            }
        }
        this.setState({form})
    }
    onChange (name,value,e) {
        e&&e.stopPropagation&&e.stopPropagation() // 阻止事件冒泡
        // console.debug(name,value);
        // 不直接操作原有的数据
        const form = Object.assign({},this.state.form)
        form[name] = value
        this.setState(
            {form}
        )
    }
    checkbox (name,value,e) {
        e&&e.stopPropagation&&e.stopPropagation() // 阻止事件冒泡
        console.debug(name,value);
        const form = Object.assign({},this.state.form)
        form[name] = value
        this.setState(
            {form}
        )
    }
    componentDidHide() { }
    render() {
        console.debug('form-props->', this.state)
        const { jSub,form } = this.state
        return (<AtForm onSubmit={this.onSubmit.bind(this)} onReset={this.onReset.bind(this)}>
            {jSub&&jSub.map((value,index)=>{
                return (value.name=="input"?<View key={index}>{
                    value.props.data&&value.props.data.map((v,i)=>{
                        return (<AtInput key={i} onChange={this.onChange.bind(this,v.name)} value={form[v.name]}></AtInput>)
                    })
                }</View>:
                value.name=="choose"?(
                <AtCheckbox key={index} onChange={this.checkbox.bind(this,value.props.name)} selectedList={form[value.props.name]} options={value.props.data}></AtCheckbox>
                ):
                <View key={index}>没有找到组件</View>)
            })}
            <AtButton formType='submit'>提交</AtButton>
            <AtButton formType='reset'>重置</AtButton>
        </AtForm>)
    }
}

@taro-bot
Copy link

taro-bot bot commented Jan 26, 2019

欢迎提交 Issue~

如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏

如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。

Good luck and happy coding~

@luckyadam
Copy link
Member

请阅读一下 taro-ui 的上手文档
https://taro-ui.aotu.io/#/docs/quickstart

@luckyadam luckyadam added question Further information is requested answered labels Jan 27, 2019
@taro-bot
Copy link

taro-bot bot commented Jan 27, 2019

Hello~

您的问题楼上已经有了确切的回答,如果没有更多的问题这个 issue 将在 15 天后被自动关闭。

如果您在这 15 天中更新更多信息自动关闭的流程会自动取消,如有其他问题也可以发起新的 Issue。

Good luck and happy coding~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants