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

[platform] rita_114 提交组件改动:mip-msg #227

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions mip-msg/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# mip-msg

mip-msg 用于提交联系方式的组件

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

提交联系方式可以直接用官方组件 mip-form 来实现,没必要新提交组件。

https://www.mipengine.org/v2/components/dynamic-content/mip-form.html

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我这也是接手的的别人的项目,他之前这样写的,考虑到如果用mip-form改动比较大,所以就改了一下他原来的组件,就很烦

标题|内容
----|----
类型|通用
支持布局|responsive,fixed-height,fill,container,fixed
所需脚本|https://c.mipcdn.com/extensions/platform/v1/mip-msg/mip-msg.js

## 示例

### 基本用法

```html
<mip-msg popContact="Mcontact" popTel="Mtel" popInfo="Minfo" popButton="Mbutton" projectId="123">
<p contenteditable="true" id="Mcontact" placeholder="请输入您的手机号码~" ></p>
<p contenteditable="true" id="Mtel" placeholder="请输入您的姓名~" ></p>

<p contenteditable="true" id="Minfo" placeholder="请输入您的手机号码~" ></p>
<span id="Mbutton" value="立即提交" ></span>
</mip-msg>
```
## 属性

### {属性名}

说明:{说明}
必选项:{是|否}
类型:{类型}
取值范围:{取值范围}
单位:{单位}
默认值:{默认值}

## 注意事项

108 changes: 108 additions & 0 deletions mip-msg/mip-msg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/**
* @file mip-vote 组件
* @author
*/

define(function (require) {
// mip 组件开发支持 zepto
var jquery = require('zepto');
var customElement = require('customElement').create();
// 第一次进入可视区回调,只会执行一次

customElement.prototype.firstInviewCallback = function () {
var element = this.element;
// 姓名Id
var popContact = this.element.getAttribute('popContact');
// 联系方式ID
var popTel = this.element.getAttribute('popTel');
// 留言内容id
var popInfo = this.element.getAttribute('popInfo');
// checkBox
var checkBox = this.element.getAttribute('checkBox');
// 提交按钮Id
var popButton = this.element.getAttribute('popButton');
var projectId = this.element.getAttribute('projectId');
var projectIdValue = '';
var popTelValue = '';
var popContactValue = '';
var popInfoValue = '';
$('#' + checkBox).click(function () {
if ($(this).attr('checked') === 'checked') {
$(this).attr('checked', false);
$(this).css('background', '#999');
} else {
$(this).attr('checked', 'checked');
$(this).css('background', '#33bd57');
}
});
// 点击按钮
$('#' + popButton + '').click(function () {
var tval = $('#' + popTel + '').text();
var add = true;
var reTel = /^1\d{10}$/;
var reg = /^0\d{2,3}-\d{7,8}(-\d{1,6})?$/;
// 判断名字是否为空
if (popContact !== '') {
if ($.trim($('#' + popContact + ' ').text()) === '') {
$('#' + popContact + ' ').attr('placeholder', '请输入你的姓名');
$('#' + popContact + ' ').css('border-color', '#FF0000');
}
else {
$('#' + popContact + '').css('border-color', '#d2d2d2');
popContactValue = $.trim($('#' + popContact + '').text());
$('#' + popContact + '').text('');
}
}
// 判断联系方式是否为空
if ($.trim(tval) === ' ') {
$('#' + popTel + '').css('border-color', '#FF0000');
$('#' + popTel + '').attr('placeholder', '请输入你的手机号码');
return;
}
else if (reTel.test(tval) === false && reg.test(tval) === false) {
$('#' + popTel + '').css('border-color', '#FF0000');
$('#' + popTel + '').text('');
$('#' + popTel + '').attr('placeholder', '输入的联系方式不正确');
return;
}
else {
$('#' + popTel + '').css('border-color', '#d2d2d2');
popTelValue = $.trim(tval);
}
if (popInfo !== '') {
popInfoValue = $.trim($('#' + popInfo + '').text());
$('#' + popInfo + '').text('');
}
var loginReqbody = {
'tid': projectId,
'type': 'addMsg',
'tel': popTelValue,
'popInfo': popInfoValue,
'popContact': popContactValue
};
if ($('#' + checkBox).attr('checked') === 'checked') {
$.ajax({
url: 'https://m.53.com.cn/common/mipwebdo.ashx',
type: 'POST',
async: false,
data: JSON.stringify(loginReqbody),
error: function () {
alert('留言失败2');
},
success: function (data, status) {
if (status = 'success' && data !== '') {
alert(data);
$('#' + popTel + '').text('');
} else {
alert('留言失败3');
}
}
});
}
else {
alert('请先同意《53加盟网服务条款》');
}
});
};
return customElement;
});
14 changes: 14 additions & 0 deletions mip-msg/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "mip-msg",
"version": "1.4.2",
"description": "用来进行提交留言的小组件",
"contributors": [
{
"name": "LaoWang",
"email": "[email protected]"
}
],
"engines": {
"mip": ">=1.1.0"
}
}