Browse Source

修复datetimepicker加载中文语音失败

wechat_public_accounts
blobt 5 years ago
parent
commit
b269014290
  1. 6
      console/controllers/TestController.php
  2. 7
      kcadmin/views/category/_form.php
  3. 2
      vendor/blobt/web/DatetimepickBootstrapAsset.php
  4. 100
      vendor/blobt/widgets/Icheck.php
  5. 6
      vendor/blobt/widgets/Select2.php

6
console/controllers/TestController.php

@ -17,11 +17,11 @@ class TestController extends Controller {
//Yii::$aa->security->generateRandomString(8); //Yii::$aa->security->generateRandomString(8);
$security = Yii::createObject("yii\base\Security"); $security = Yii::createObject("yii\base\Security");
$n = 0; $n = 0;
for ($i = 1; $i < 100000; $i++) {
for ($i = 1; $i < 1000; $i++) {
//$key = $security->generateRandomString(8); //$key = $security->generateRandomString(8);
$key = rand(10000000, 99999999); $key = rand(10000000, 99999999);
/*$key = strtolower($key);
$key = str_replace(['_', '-'], 'a', $key);*/
//$key = strtolower($key);
//$key = str_replace(['_', '-'], 'a', $key);
$ret[$key] += 1; $ret[$key] += 1;
} }

7
kcadmin/views/category/_form.php

@ -5,6 +5,7 @@ use yii\widgets\ActiveForm;
use blobt\widgets\DatePicker; use blobt\widgets\DatePicker;
use blobt\widgets\Select2; use blobt\widgets\Select2;
use blobt\widgets\DatetimePicker; use blobt\widgets\DatetimePicker;
use blobt\widgets\Icheck;
/* @var $this yii\web\View */ /* @var $this yii\web\View */
/* @var $model common\models\Category */ /* @var $model common\models\Category */
@ -15,14 +16,14 @@ use blobt\widgets\DatetimePicker;
<?php $form = ActiveForm::begin(); ?> <?php $form = ActiveForm::begin(); ?>
<div class="box-body"> <div class="box-body">
<?= $form->field($model, 'cat_name')->textInput(['maxlength' => true]) ?> <?= $form->field($model, 'cat_name')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'icon')->textInput(['maxlength' => true]) ?> <?= $form->field($model, 'icon')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'icon_type')->widget(Select2::className(), ["data" => $model::$iconType]) ?> <?= $form->field($model, 'icon_type')->widget(Select2::className(), ["data" => $model::$iconType]) ?>
<?= $form->field($model, 'icon_type')->checkbox(["a" => "A", "b" => "B"]) ?>
<?= $form->field($model, 'icon_type')->widget(Icheck::className(), ["items" => ["a" => "A", "b" => "B"]]) ?>
<?= $form->field($model, 'description')->textarea(['rows' => 6]) ?> <?= $form->field($model, 'description')->textarea(['rows' => 6]) ?>

2
vendor/blobt/web/DatetimepickBootstrapAsset.php

@ -41,7 +41,7 @@ class DatetimepickBootstrapAsset extends AssetBundle {
]; ];
public $js = [ public $js = [
'js/bootstrap-datetimepicker.min.js', 'js/bootstrap-datetimepicker.min.js',
'js/locales/bootstrap-datepicker.zh-CN.min.js',
'js/locales/bootstrap-datetimepicker.zh-CN.js',
]; ];
public $depends = [//所有依赖 public $depends = [//所有依赖
'yii\web\JqueryAsset', 'yii\web\JqueryAsset',

100
vendor/blobt/widgets/Icheck.php

@ -0,0 +1,100 @@
<?php
/*
* The MIT License
*
* Copyright 2019 Blobt.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
namespace blobt\widgets;
use yii\widgets\InputWidget;
use Yii;
use yii\base\InvalidConfigException;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use blobt\web\IcheckAsset;
/**
* Description of Icheck
*
* @author Blobt
* @email 380255922@qq.com
* @created Sep 12, 2019
*/
class Icheck extends InputWidget {
/**
* @var var checkbox的选项
*/
public $items = [];
/**
* @inheritdoc
* @throws \ReflectionException
* @throws \yii\base\InvalidConfigException
*/
public function run() {
$this->registerAsset();
$this->registerJs();
return $this->renderCheckBox();
}
/**
* 初始化
*/
public function init() {
parent::init();
if ($this->hasModel() && !isset($options['name'])) {
$this->name = $this->options['name'] = Html::getInputName($this->model, $this->attribute);
}
if (count($this->items) > 1) {
$this->name .="[]";
}
}
/**
* 注册js和css
*/
protected function registerAsset() {
$view = $this->getView();
IcheckAsset::register($view);
}
/**
* 注册js
*/
protected function registerJs() {
$js = <<<SCRIPT
$("input[name='{$this->name}']").iCheck();
SCRIPT;
$this->getView()->registerJs($js);
}
protected function renderCheckBox() {
$line = [];
foreach ($this->items as $key => $val) {
$line[] = Html::tag('input', $key, ["type" => "radio", "name" => $this->name]);
}
return implode("\n", $line);
}
}

6
vendor/blobt/widgets/Select2.php

@ -63,6 +63,9 @@ class Select2 extends InputWidget {
return $this->renderSelect(); return $this->renderSelect();
} }
/**
* 初始化
*/
public function init() { public function init() {
parent::init(); parent::init();
if ($this->hasModel() && !isset($options['name'])) { if ($this->hasModel() && !isset($options['name'])) {
@ -78,6 +81,9 @@ class Select2 extends InputWidget {
Select2Asset::register($view); Select2Asset::register($view);
} }
/**
* 注册js
*/
protected function registerSelect2Js() { protected function registerSelect2Js() {
$js = <<<SCRIPT $js = <<<SCRIPT
$('#category-icon_type').select2(); $('#category-icon_type').select2();

Loading…
Cancel
Save